Running and Restarting a Rails Puma Webserver in Production

Let’s dive into how to run a Rails Puma webserver process and how to restart it.

As you may be aware, Puma is the default webserver for Rails. Running the webserver locally is simple (bin/rails s). Running Puma on a production webserver is not so easy and there are a few considerations:

  1. You’ll want to run Rails in production mode
  2. You’ll want to run Puma as a continuous background process

Here’s how we run Puma on our webservers:

RAILS_ENV=production bundle exec puma --daemon --bind unix://tmp/sockets/puma.sock --state tmp/sockets/puma.state --control unix://tmp/sockets/pumactl.sock

Let’s break it down.

To restart Puma, you can use pumactl. This command allows you to interact with a running Puma server. You just need to specify the state file and pass the restart param:

bundle exec pumactl --state tmp/sockets/puma.state restart