如何获得与Puma和Capistrano一起部署的Rails应用程序以重新启动

时间:2016-07-07 16:31:23

标签: ruby-on-rails ruby nginx puma systemd

我已成功使用Capistrano成功部署了Rails 4,Puma,Nginx应用程序。当我部署cap production deploy时,一切都很有效。我的问题是,如果服务器因任何原因重新启动或者它崩溃了,它就不会重新启动。

我在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.

我在这里做错了什么?

1 个答案:

答案 0 :(得分:4)

我有类似的服务,但我宣布略有不同的/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