Using linger with Ruby on Rails


This article explains how to run Puma with Ruby on Rails using Linger. This combination allows your app to run persistent processes and your services to restart if your app crashes or the server reboots.


This article assumes you have completed the following steps:

Step 1 — Install Ruby and Rails

Install Ruby and Rails using the following guides.


Install a new version of Ruby on your VPS. See the following article for more information:


The following article uses the Rails app name of blog, but you can name it anything you like.

View steps #1-7.3 in the following guide to configure Rails:

Step 2 — Install Puma

View the following guides for steps on installing Puma:

Edit the puma.rb file

Navigate into the following directory:


Edit the puma.rb file to change the default port # to the port you chose when creating the Proxy Server in the panel. This example uses port 8003:

port ENV.fetch("PORT") {8003}

Start the Puma web server

Navigate into the following directory:


Run the following command:

[server]$ bin/rails server

To stop the server, press CTRL + C.

Troubleshooting an error

If you get a blocked host error about your app domain, you'll need to add a line to the development.rb file.

Navigate into the following directory:


Edit the development.rb file. Under the config.enable_reloading = true line, add the following:

config.hosts << /example\.com/

Restart your VPS and relaunch Puma. The error should now be resolved.

Step 3 — Install Linger

To install linger under your user, log in to your server via SSH and run the following command:

[server]$ loginctl enable-linger

This command will not respond with any output.

Step 4 — Configure Puma for Systemd user units

View the official guide for further details:

To configure Puma for Systemd user units:

  1. Create a file named puma.service in the .config/systemd/user directory:
    [server]$ nano ~/.config/systemd/user/puma.service
  2. Add the following code to this file:
    Description=Puma instance to serve application
    ExecStart=/path/to/your/app/bin/puma -C config/puma.rb -e production
    ExecReload=/bin/kill -s HUP $MAINPID
  3. Edit the highlighted lines above as follows:
    • WorkingDirectory: The path to your website application.
    • ExecStart: The path to your puma installation.
  4. Enable the user unit for puma:
    [server]$ systemctl --user enable puma
  5. Start the unit with puma:
    [server]$ systemctl --user start puma
  6. Confirm it is running:
    [server]$ systemctl --user status puma

Your app's services will now automatically restart when the server reboots or if the application crashes.

See also

Did this article answer your questions?

Article last updated PST.

Still not finding what you're looking for?