Setting up Puma as Systemd service in Ubuntu 18

Puma running as a service using systemd

After struggling a lot with setting up Puma on many machines i extracted a set of steps to follow to install puma as a service on systemd over Ubuntu 18.

Assuming that you already have ruby installed with one of:

  1. Plain ol’ Ruby
  2. RBenv
  3. RVM (My favorite)
  4. Chruby

For this guide my user is ubuntu, but you can do the same but be aware to replace the paths where they correspond.

First install the puma gem: $ gem install puma (Consider Ruby version requirements in the puma github page). Also install bundler: gem install bundler .

After installing write down the path corresponding to your ruby installation by typing: which bundle in my case the output is:


Place in your project a puma configuration file in the /config/puma directory. We will use it later as systemd will use it to start the puma process.

My puma config file.

I’m assuming production environment for the above file, but you can change it to suit your needs.

Now use the following snippet and adjust the paths to your setup.

My puma systemd setup.

Replace the following parts with your settings:

  1. WorkingDirectory to the root path of your rails application.
  2. User with the OS user that will launch the puma service. In my case ubuntu user has the rvm installation and puma execution.
  3. ExecStart is conformed by the puma executable full path, an argument, a path to the puma config file and a final argument. Just adjust the paths of puma and bundler also proper environment.

Now create the puma.service file in /etc/systemd/system/puma.service . Type in the following commands to reload and enable the new service.

$ sudo systemctl daemon-reload
$ sudo systemctl enable puma

Now when you type in sudo service puma start you will get puma running. You can make sure the state of the service by typing sudo service puma status in my case the output is:

puma[31515]: [31515] Puma starting in cluster mode...
puma[31515]: [31515] * Version 3.12.0 (ruby 2.3.0-p0), codename: Llamas in Pajamas
puma[31515]: [31515] * Min threads: 1, max threads: 2
puma[31515]: [31515] * Environment: production
puma[31515]: [31515] * Process workers: 2
puma[31515]: [31515] * Phased restart available
puma[31515]: [31515] * Listening on unix:///path/to/my/rails-app/puma.sock
puma[31515]: [31515] * Daemonizing...
systemd[1]: Started Puma.

Also with the command ps aux | grep puma :

ubuntu 31541 puma 3.12.0 (unix:///path/to/my/rails-app/puma.sock) [20190807233351]
ubuntu 31548 puma: cluster worker 0: 31541 [20190807233351]
ubuntu 31550 puma: cluster worker 1: 31541 [20190807233351]

If this does not happen you would check what went wrong using the command $ journalctl -xe and pay carefully attention to the error shown, most commonly is a path issue on your gems or working directories.

Now that your app server is setup with puma service and is running you can reverse proxy using nginx web server so your rails app is available to the outside world, you can now set up Nginx in Ubuntu 18 for a Ruby on Rails app using Puma.

Full Stack Ruby on Rails Developer. Software Engineer @ SpiderDoor LLC

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

Instructions on how to join Tokenplay IDO on PolyLAUNCH

OCI Vault Secrets

Getting a Hang of IT Project Management Landscape In 2021

Cool off bro — How to do a simple cooldown system.

How to read 🗞 Google News RAPIDLY using a short python script


Google Summer of Code 2020: Week 3— Gitlab Data Collection Workers

4 Free CDN Hosting Providers to Speed Up Your Business Website

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
David Mauricio

David Mauricio

Full Stack Ruby on Rails Developer. Software Engineer @ SpiderDoor LLC

More from Medium

Working with ruby C extensions on Mac

Setting up Ruby on Rails with RVM, Puma, Mina, Nginx, Sidekiq and Redis on Amazon Linux 2

Writing clean code with Ruby on Rails

ruby-build: definition not found: x.x.x