简体   繁体   中英

How to get a Rails App Deployed with Puma and Capistrano to start on reboot

I've managed to successfully deploy a Rails 4, Puma, Nginx App using Capistrano. When I deploy cap production deploy everything works great. My problem is if the server reboots for whatever reason or if it crashes, it doesn't restart.

I'm using a Debian 8 on DigitalOcean. It seems Debian 8 uses systemd , so I've followed the instructions from Puma but it didn't work. After some research I've found a couple more scripts and the one that seemed most sensible was this:

[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

I've saved the above file in /etc/systemd/system/rails-puma.service then I've enabled it: sudo systemctl enable rails.service and finally started it: sudo systemctl start rails-puma.service

Which unfortunately didn't work. This is the result of 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.

What am I doing wrong here?

I have a similar service but I declared slightly different /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

then in /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 )

and in /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 )

remember after setting up to execute

chmod +x /etc/puma/puma-start
chmod +x /etc/puma/puma-stop
systemctl enable puma

and then to test

systemctl start puma
systemctl stop puma
systemctl restart puma
systemctl status puma

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM