我已经成功地使用Capistrano部署了Rails 4,Puma,Nginx App.当我部署上限生产时,部署一切正常.我的问题是,如果服务器由于某种原因而重新启动,或者崩溃了,它就不会重新启动.
我在DigitalOcean上使用Debian 8.似乎Debian 8使用systemd,所以我遵循了Puma的说明,但是没有用.经过一番研究,我发现了另外两个脚本,其中最明智的一个是:
[Unit]
Description=Rails-Puma Webserver
[Service]
Type=simple
User=myuser
WorkingDirectory=/home/myuser/apps/myapp
ExecStart=/home/myuser/.rvm/rubies/ruby-2.2.2/bin/systemd_rails server -e production
TimeoutSec=15
Restart=always
[Install]
WantedBy=multi-user.target
我已将以上文件保存在/etc/systemd/system/rails-puma.service中,然后启用了它:sudo systemctl enable rails.service并最终启动了它:sudo systemctl start rails-puma.service
不幸的是,这没有用.这是sudo systemctl status rails-puma.service的结果:
● rails-puma.service - Rails-Puma Webserver
Loaded: loaded (/etc/systemd/system/rails-puma.service; enabled)
Active: failed (Result: start-limit) since Thu 2016-07-07 12:11:58 EDT; 4s ago
Process: 4373 ExecStart=/home/myuser/.rvm/rubies/ruby-2.2.2/bin/systemd_rails server -e production (code=exited, status=203/EXEC)
Main PID: 4373 (code=exited, status=203/EXEC)
Jul 07 12:11:58 mrcProd systemd[1]: rails-puma.service: main process exited, code=exited, status=203/EXEC
Jul 07 12:11:58 mrcProd systemd[1]: Unit rails-puma.service entered failed state.
Jul 07 12:11:58 mrcProd systemd[1]: rails-puma.service start request repeated too quickly, refusing to start.
Jul 07 12:11:58 mrcProd systemd[1]: Failed to start Rails-Puma Webserver.
Jul 07 12:11:58 mrcProd systemd[1]: Unit rails-puma.service entered failed state.
我在这里做错了什么?
解决方法:
我有类似的服务,但我声明/etc/systemd/system/puma.service略有不同
[Unit]
Description=Puma Control
After=network.target auditd.service
[Service]
Type=oneshot
RemainAfterExit=yes
ExecStart=/etc/puma/puma-start
ExecStop=/etc/puma/puma-stop
[Install]
WantedBy=multi-user.target
然后在/ etc / puma / puma-start中
#!/bin/bash -
cd /home/changeuser/apps/changeapp/current && ( export RACK_ENV="production" ; /home/changeuser/.rvm/bin/rvm default do bundle exec puma -C /home/changeuser/apps/changeapp/shared/puma.rb --daemon )
并在/ etc / puma / puma-stop中
#!/bin/bash -
cd /home/changeuser/apps/changeapp/current && ( export RACK_ENV="production" ; /home/changeuser/.rvm/bin/rvm default do bundle exec pumactl -S /home/changeuser/apps/changeapp/shared/tmp/pids/puma.state stop )
记得设置后执行
chmod +x /etc/puma/puma-start
chmod +x /etc/puma/puma-stop
systemctl enable puma
然后测试
systemctl start puma
systemctl stop puma
systemctl restart puma
systemctl status puma