Skip to content

Instantly share code, notes, and snippets.

@DSKonstantin
Last active November 16, 2023 16:14
Show Gist options
  • Star 4 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save DSKonstantin/708f346f1cf62fb6d61bf6592e480781 to your computer and use it in GitHub Desktop.
Save DSKonstantin/708f346f1cf62fb6d61bf6592e480781 to your computer and use it in GitHub Desktop.
Auto start puma via systemctl
Article: https://github.com/puma/puma/blob/master/docs/systemd.md
#1 nano /etc/systemd/system/puma.service
#2 paste from puma.service
Commands:
# After installing or making changes to puma.service
systemctl daemon-reload
# Enable so it starts on boot
systemctl enable puma.service
# Initial start up.
systemctl start puma.service
# Check status
systemctl status puma.service
# A normal restart. Warning: listeners sockets will be closed
# while a new puma process initializes.
systemctl restart puma.service
[Unit]
Description=Puma HTTP Server
After=network.target
[Service]
Type=simple
User=root
Group=root
WorkingDirectory=<path_to_project>/current
Environment=SECRET_KEY_BASE='<SECRET KEY>'
ExecStart=/usr/local/rvm/bin/rvm <ruby_version>@<gemset_name> do bundle exec puma -C <path_to_project>/shared/puma.rb --daemon
ExecStop=/usr/local/rvm/bin/rvm <ruby_version>@<gemset_name> do bundle exec pumactl -S <path_to_project>/shared/tmp/pids/puma.state -F <path_to_project>/shared/puma.rb stop
#Restart=always
Restart=on-failure
[Install]
WantedBy=multi-user.target
[Unit]
Description=Puma HTTP Server
After=network.target
[Service]
Type=simple
User=root
Group=root
WorkingDirectory=<path_to_project>/current
Environment=RAILS_ENV=production
EnvironmentFile=<path_to_project>/current/config/application.yml
PIDFile=<path_to_project>/shared/tmp/pids/puma.pid
ExecStart=/usr/local/rvm/bin/rvm <ruby_version>@<gemset_name> do bundle exec puma -C <path_to_project>/shared/puma.rb --daemon
ExecStop=/usr/local/rvm/bin/rvm <ruby_version>@<gemset_name> do bundle exec pumactl -S <path_to_project>/shared/tmp/pids/puma.state -F <path_to_project>/shared/puma.rb stop
TimeoutSec=15
KillMode=process
#Restart=always
Restart=on-failure
[Install]
WantedBy=multi-user.target
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment