Skip to content

Instantly share code, notes, and snippets.

@arteezy
Last active October 26, 2024 10:55
Show Gist options
  • Save arteezy/5d53d99f6ee617fae1f0db0576fdd418 to your computer and use it in GitHub Desktop.
Save arteezy/5d53d99f6ee617fae1f0db0576fdd418 to your computer and use it in GitHub Desktop.
Manage Puma with systemd 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
@promisepreston
Copy link

promisepreston commented Dec 16, 2019

Thank you so much for this.
I made some modification to mine.

Puma Service Configuration

[Unit]
Description=Puma HTTP Server
After=network.target

[Service]
# Foreground process (do not use --daemon in ExecStart or config.rb)
Type=simple

# Preferably configure a non-privileged user
User=deploy

# The path to the your application code root directory
WorkingDirectory=/home/deploy/my-app

# The command to start Puma
ExecStart=/home/deploy/.rbenv/shims/puma -C /home/deploy/my-app/config/puma.rb

# The command to stop Puma
ExecStop=/home/deploy/.rbenv/shims/puma -S /home/deploy/my-app/config.puma.rb

# Path to PID file so that systemd knows which is the master process
PIDFile=/home/deploy/my-app/tmp/pids/puma.pid

# Should systemd restart puma?
# Use "no" (the default) to ensure no interference when using
# stop/start/restart via `pumactl`.  The "on-failure" setting might
# work better for this purpose, but you must test it.
# Use "always" if only `systemctl` is used for start/stop/restart, and
# reconsider if you actually need the forking config.
Restart=always

[Install]
WantedBy=multi-user.target

https://stackoverflow.com/a/59363127/10907864

@nirmal-vaja
Copy link

Hey I did the same but that prompt me to enter password I am not sure what the password is .... Can anyone help me on this ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment