Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Manage Puma with systemd on Ubuntu 16.04 and rbenv
[Unit]
Description=Puma Rails Server
After=network.target
[Service]
Type=simple
User=deploy
WorkingDirectory=/home/deploy/app/current
ExecStart=/home/deploy/.rbenv/bin/rbenv exec bundle exec puma -C /home/deploy/app/shared/config/puma.rb
ExecStop=/home/deploy/.rbenv/bin/rbenv exec bundle exec pumactl -S /home/deploy/app/shared/tmp/pids/puma.state stop
TimeoutSec=15
Restart=always
[Install]
WantedBy=multi-user.target
@FinnWoelm

This comment has been minimized.

Copy link

FinnWoelm commented Aug 13, 2017

Thanks a lot! 🎉

@DaveCollinsJr

This comment has been minimized.

Copy link

DaveCollinsJr commented Oct 5, 2017

Fantastic. Thanks for taking the time to summarize!

@samholst

This comment has been minimized.

Copy link

samholst commented Apr 18, 2018

You saved my life! After 5 hours of trying I found this! Thanks!

@ukazap

This comment has been minimized.

Copy link

ukazap commented Sep 7, 2018

is this only for one rails app?

@loop23

This comment has been minimized.

Copy link

loop23 commented Sep 12, 2018

@ukazap yes for the one in /home/deploy/app/current

@rromanchuk

This comment has been minimized.

Copy link

rromanchuk commented Oct 27, 2018

For whatever reason I had to use ExecStart=/bin/bash -lc 'bundle exec puma -C {deploy_dir}/shared/config/puma/production.rb' in my puma.service, otherwise i was getting the error below. Interestingly enough, i never noticed until i was tailing the logs because it was just immediately relaunching so i didn't even notice

Oct 24 08:33:37  puma[14012]: [14012] - Gracefully shutting down workers...
Oct 24 08:33:37 puma[14012]: On worker shutdown...
Oct 24 08:33:37 puma[14012]: On worker shutdown...
Oct 24 08:33:37  puma[18850]: Command stop sent success
Oct 24 08:33:37  puma[14012]: On worker shutdown...
Oct 24 08:33:37 puma[14012]: [14012] - Gracefully shutting down workers...
Oct 24 08:33:37puma[14012]: bundler: failed to load command: puma (/var/www/spar/releases/20181024082043Z/vendor/bundle/ruby/2.5.0/bin/puma)
Oct 24 08:33:37 ipuma[14012]: Errno::ECHILD: No child processes
Oct 24 08:33:37  puma[14012]:   /var/www/spar/shared/vendor/bundle/ruby/2.5.0/gems/puma-3.12.0/lib/puma/cluster.rb:38:in `waitpid'
Oct 24 08:33:37  puma[14012]:   /var/www/spar/shared/vendor/bundle/ruby/2.5.0/gems/puma-3.12.0/lib/puma/cluster.rb:38:in `block in stop_workers'
Oct 24 08:33:37 puma[14012]:   /var/www/spar/shared/vendor/bundle/ruby/2.5.0/gems/puma-3.12.0/lib/puma/cluster.rb:38:in `each'
Oct 24 08:33:37  puma[14012]:   /var/www/spar/shared/vendor/bundle/ruby/2.5.0/gems/puma-3.12.0/lib/puma/cluster.rb:38:in `stop_workers'
Oct 24 08:33:37 puma[14012]:   /var/www/spar/shared/vendor/bundle/ruby/2.5.0/gems/puma-3.12.0/lib/puma/cluster.rb:391:in `block in setup_signals'
Oct 24 08:33:37  puma[14012]:   /var/www/spar/shared/vendor/bundle/ruby/2.5.0/gems/puma-3.12.0/lib/puma/cluster.rb:515:in `rescue in run'
Oct 24 08:33:37puma[14012]:   /var/www/spar/shared/vendor/bundle/ruby/2.5.0/gems/puma-3.12.0/lib/puma/cluster.rb:478:in `run'
Oct 24 08:33:37  puma[14012]:   /var/www/spar/shared/vendor/bundle/ruby/2.5.0/gems/puma-3.12.0/lib/puma/launcher.rb:184:in `run'
Oct 24 08:33:37  puma[14012]:   /var/www/spar/shared/vendor/bundle/ruby/2.5.0/gems/puma-3.12.0/lib/puma/cli.rb:78:in `run'
Oct 24 08:33:37  puma[14012]:   /var/www/spar/releases/20181024082043Z/vendor/bundle/ruby/2.5.0/gems/puma-3.12.0/bin/puma:10:in `<top (required)>'
Oct 24 08:33:37 i puma[14012]:   /var/www/spar/releases/20181024082043Z/vendor/bundle/ruby/2.5.0/bin/puma:23:in `load'
Oct 24 08:33:37  puma[14012]:   /var/www/spar/releases/20181024082043Z/vendor/bundle/ruby/2.5.0/bin/puma:23:in `<top (required)>'
Oct 24 08:33:37  systemd[1]: puma.service: Main process exited, code=exited, status=1/FAILURE
Oct 24 08:33:37  systemd[1]: puma.service: Failed with result 'exit-code'.
Oct 24 08:33:37 systemd[1]: Stopped puma.
-- Subject: Unit puma.service has finished shutting down
@rromanchuk

This comment has been minimized.

Copy link

rromanchuk commented Oct 27, 2018

actually i just figured it out, it was the ExecStop declaration that was causing it, once i removed that, i had proper restarts

@rromanchuk

This comment has been minimized.

Copy link

rromanchuk commented Oct 27, 2018

blah, because i'm using sockets. puma's own documentation is correct https://github.com/puma/puma/blob/master/docs/systemd.md

@dougcouvillion

This comment has been minimized.

Copy link

dougcouvillion commented Nov 25, 2018

Thank you! This was a life saver.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.