我使用capistrano部署了项目,但是在服务器重启后puma没有启动..
我应该做 - > 限制生产美洲狮:每次开始
我试过了:
的 /etc/init.d/myscript
#!/bin/sh
/etc/init.d/puma_start.sh
puma_start.sh
#!/bin/bash
puma -C /root/project/shared/puma.rb
但是,我有错误
/usr/local/rvm/rubies/ruby-2.3.3/lib/ruby/site_ruby/2.3.0/rubygems.rb:270:in `find_spec_for_exe': can't find gem puma (>= 0.a) (Gem::GemNotFoundException)
from /usr/local/rvm/rubies/ruby-2.3.3/lib/ruby/site_ruby/2.3.0/rubygems.rb:298:in `activate_bin_path'
from /usr/local/rvm/gems/ruby-2.3.3@project/bin/puma:22:in `<main>'
from /usr/local/rvm/gems/ruby-2.3.3@project/bin/ruby_executable_hooks:15:in `eval'
from /usr/local/rvm/gems/ruby-2.3.3@project/bin/ruby_executable_hooks:15:in `<main>'
如果我放入控制台root@host:~# puma -C /root/project/shared/puma.rb
它可以工作,而且所有的都可以。
我想我没有正确的宝石美洲狮的路径
如何在服务器重启后执行puma autostart 谢谢
答案 0 :(得分:0)
我发现了http://codepany.com/blog/rails-5-puma-capistrano-nginx-jungle-upstart/
这对我有帮助 - &gt;
cd ~
$ wget https://raw.githubusercontent.com/puma/puma/master/tools/jungle/upstart/puma-manager.conf
$ wget https://raw.githubusercontent.com/puma/puma/master/tools/jungle/upstart/puma.conf
打开下载的puma.conf文件,并为setuid和setguid设置系统的用户帐户。 (在我们的例子中,我们使用root帐户,但建议使用权限较低的帐户):
vim puma.conf
setuid root
setgid root
将下载的upstart文件移动到/ etc / init并创建另一个puma.conf
$ sudo cp puma.conf puma-manager.conf /etc/init
$ sudo touch /etc/puma.conf
打开/etc/puma.conf并添加app app:
的路径/root/name_of_your_app/current
打开/etc/init/puma.conf,找到类似的东西
exec bundle exec puma -C /root/project/shared/puma.rb
并将路径替换为puma.rb文件
谢谢
答案 1 :(得分:0)
从Ubuntu 16.04开始,建议使用 systemctl 。在我使用新贵之前。 我为自己创建了此说明。也许对某人有用。
https://gist.github.com/DSKonstantin/708f346f1cf62fb6d61bf6592e480781
说明:
Article: https://github.com/puma/puma/blob/master/docs/systemd.md
#1 nano /etc/systemd/system/puma.service
#2 paste from puma.service
Commands:
# After installing or making changes to puma.service
systemctl daemon-reload
# Enable so it starts on boot
systemctl enable puma.service
# Initial start up.
systemctl start puma.service
# Check status
systemctl status puma.service
# A normal restart. Warning: listeners sockets will be closed
# while a new puma process initializes.
systemctl restart puma.service
puma.service文件
[Unit]
Description=Puma HTTP Server
After=network.target
[Service]
Type=simple
User=root
Group=root
WorkingDirectory=<path_to_project>/current
Environment=SECRET_KEY_BASE='<SECRET KEY>'
ExecStart=/usr/local/rvm/bin/rvm <ruby_version>@<gemset_name> do bundle exec puma -C <path_to_project>/shared/puma.rb --daemon
ExecStop=/usr/local/rvm/bin/rvm <ruby_version>@<gemset_name> do bundle exec pumactl -S <path_to_project>/shared/tmp/pids/puma.state -F <path_to_project>/shared/puma.rb stop
#Restart=always
Restart=on-failure
[Install]
WantedBy=multi-user.target
答案 2 :(得分:0)
实际上有一种非常简单的方法可以诊断和解决这个问题:
1. 找到您的 rvm 可执行文件。
which rvm
就我而言是:
/usr/share/rvm/bin/rvm
...但你的可能不同!因此,您必须首先执行此操作才能找出可执行文件的位置。
2.找出您的服务器运行的 Ruby 版本。
ruby --version
对我来说是 2.6.2。您只需要那个版本号。没有别的。
3.尝试类似康斯坦丁推荐的方法,但改为这样做:
[Unit]
Description=Puma HTTP Server
After=network.target
[Service]
Type=simple
User=root
Group=root
WorkingDirectory= /var/www/your/current
ExecStart=/usr/share/rvm/bin/rvm 2.6.2 do bundle exec pumactl -S /var/www/your/shared/tmp/pids/puma.state -F /var/www/your/shared/puma.rb start
ExecStop=/usr/share/rvm/bin/rvm 2.6.2 do bundle exec pumactl -S /var/www/your/shared/tmp/pids/puma.state -F /var/www/your/shared/puma.rb stop
# Restart=always
Restart=on-failure
[Install]
WantedBy=multi-user.target
4.然后是一个简单的问题:
systemctl daemon-reload
systemctl enable puma.service
systemctl start puma.service
systemctl status puma.service
那就这样吧!下次启动服务器时,puma 应该可以正常启动。