Wag*_*sUK 3 ruby ruby-on-rails nginx systemd puma
我已经成功使用 Capistrano 部署了 Rails 4、Puma、Nginx 应用程序。当我部署时cap production deploy一切都很好。我的问题是,如果服务器由于某种原因重新启动或者崩溃,它不会重新启动。
我在 DigitalOcean 上使用 Debian 8。Debian 8 似乎使用了,所以我按照Pumasystemd的说明进行操作,但它不起作用。经过一番研究,我发现了更多的脚本,其中最合理的一个是:
[Unit]\nDescription=Rails-Puma Webserver\n\n[Service]\nType=simple\nUser=myuser\nWorkingDirectory=/home/myuser/apps/myapp\nExecStart=/home/myuser/.rvm/rubies/ruby-2.2.2/bin/systemd_rails server -e production\nTimeoutSec=15\nRestart=always\n\n[Install]\nWantedBy=multi-user.target\nRun Code Online (Sandbox Code Playgroud)\n\n我保存了上面的文件,然后/etc/systemd/system/rails-puma.service启用了它:sudo systemctl enable rails.service最后启动了它:sudo systemctl start rails-puma.service
不幸的是这没有用。这是以下结果sudo systemctl status rails-puma.service:
\xe2\x97\x8f rails-puma.service - Rails-Puma Webserver\n Loaded: loaded (/etc/systemd/system/rails-puma.service; enabled)\n Active: failed (Result: start-limit) since Thu 2016-07-07 12:11:58 EDT; 4s ago\n Process: 4373 ExecStart=/home/myuser/.rvm/rubies/ruby-2.2.2/bin/systemd_rails server -e production (code=exited, status=203/EXEC)\n Main PID: 4373 (code=exited, status=203/EXEC)\n\nJul 07 12:11:58 mrcProd systemd[1]: rails-puma.service: main process exited, code=exited, status=203/EXEC\nJul 07 12:11:58 mrcProd systemd[1]: Unit rails-puma.service entered failed state.\nJul 07 12:11:58 mrcProd systemd[1]: rails-puma.service start request repeated too quickly, refusing to start.\nJul 07 12:11:58 mrcProd systemd[1]: Failed to start Rails-Puma Webserver.\nJul 07 12:11:58 mrcProd systemd[1]: Unit rails-puma.service entered failed state.\nRun Code Online (Sandbox Code Playgroud)\n\n我在这里做错了什么?
\n我有类似的服务,但我声明略有不同/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
Run Code Online (Sandbox Code Playgroud)
然后在/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 )
Run Code Online (Sandbox Code Playgroud)
并在/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 )
Run Code Online (Sandbox Code Playgroud)
设置完后记得执行
chmod +x /etc/puma/puma-start
chmod +x /etc/puma/puma-stop
systemctl enable puma
Run Code Online (Sandbox Code Playgroud)
然后测试
systemctl start puma
systemctl stop puma
systemctl restart puma
systemctl status puma
Run Code Online (Sandbox Code Playgroud)