Skip to content

Instantly share code, notes, and snippets.

@majedbojan
Created May 19, 2021 11:41
Show Gist options
  • Save majedbojan/190c4398c215e687573c63e8e36d40b3 to your computer and use it in GitHub Desktop.
Save majedbojan/190c4398c215e687573c63e8e36d40b3 to your computer and use it in GitHub Desktop.

We used the official Capistrano recipe for Puma. capistrano-puma. It has monit scripts built-in to monitor puma server processes

OS level


Install monit

sudo apt-get update
sudo apt-get install monit

Grant access to deployment user

  • Deployment user to sudo, suppose we use ubuntu or ec2-user user for deployment then the user must be added to sudo, no password group because monit requires to be run as root service
sudo visudo

# add the following line under %sudo   ALL=(ALL:ALL) ALL
ec2-user  ALL=(ALL) NOPASSWD:ALL

Application level


Install the gem

# Gemfile
gem 'capistrano3-puma', github: 'seuros/capistrano-puma'

# in the Capfile add monit plugin
install_plugin Capistrano::Puma::Monit

This will add following rake tasks to Capistrano

cap puma:config                    # Setup Puma config file
cap puma:monit:config              # Config Puma monit-service
cap puma:monit:monitor             # Monitor Puma monit-service
cap puma:monit:restart             # Restart Puma monit-service
cap puma:monit:start               # Start Puma monit-service
cap puma:monit:stop                # Stop Puma monit-service
cap puma:monit:unmonitor           # Unmonitor Puma monit-service

Add puma user

# config/deploy.rb
set :user, 'ec2-user'

in config/deploy.rb add the following line:

cap dev puma:monit:config
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment