Puma daemon service

Deprecatation Warning : init.d was replaced by systemd since Debian 8 and Ubuntu 16.04, you should look into /docs/systemd unless you are on an older OS.

Init script to manage multiple Puma servers on the same box using start-stop-daemon.

Installation

  1. # Copy the init script to services directory
  2. sudo cp puma /etc/init.d
  3. sudo chmod +x /etc/init.d/puma
  4. # Make it start at boot time.
  5. sudo update-rc.d -f puma defaults
  6. # Copy the Puma runner to an accessible location
  7. sudo cp run-puma /usr/local/bin
  8. sudo chmod +x /usr/local/bin/run-puma
  9. # Create an empty configuration file
  10. sudo touch /etc/puma.conf

Managing the jungle

Puma apps are held in /etc/puma.conf by default. It’s mainly a CSV file and every line represents one app. Here’s the syntax:

  1. app-path,user,config-file-path,log-file-path,environment-variables

You can add an instance by editing the file or running the following command:

  1. sudo /etc/init.d/puma add /path/to/app user /path/to/app/config/puma.rb /path/to/app/log/puma.log

The config and log paths, as well as the environment variables, are optional parameters and default to:

  • config: /path/to/app/config/puma.rb
  • log: /path/to/app/log/puma.log
  • environment: (empty)

Multiple environment variables need to be separated by a semicolon, e.g.

  1. FOO=1;BAR=2

To remove an app, simply delete the line from the config file or run:

  1. sudo /etc/init.d/puma remove /path/to/app

The command will make sure the Puma instance stops before removing it from the jungle.

Assumptions

  • The script expects a temporary folder named /path/to/app/tmp/puma to exist. Create it if it’s not there by default.
    The pid and state files should live there and must be called: tmp/puma/pid and tmp/puma/state.
    You can change those if you want but you’ll have to adapt the script for it to work.

  • Here’s what a minimal app’s config file should have:

  1. pidfile "/path/to/app/tmp/puma/pid"
  2. state_path "/path/to/app/tmp/puma/state"
  3. activate_control_app