Skip to content

Instantly share code, notes, and snippets.

@clemlatz
Last active December 6, 2017 13:59
Show Gist options
  • Save clemlatz/4b00ca3b2cd566e7fef07e188cbdfaf5 to your computer and use it in GitHub Desktop.
Save clemlatz/4b00ca3b2cd566e7fef07e188cbdfaf5 to your computer and use it in GitHub Desktop.
puma daemon management

Puma daemon management

Install

  1. Save puma.rb file locally (eg. to ~/bin/puma.rb)
  2. Create alias alias p='~/bin/puma.rb in bash.rc

Usage

Start server

p

Stop server

p stop

Restart server

p restart
token = 'fou'
arg = ARGV[0] || 'start'
unless ['halt', 'restart', 'phased-restart', 'start', 'stats', 'status', 'stop', 'reload-worker-directory', 'gc', 'gc-stats'].include?(arg)
puts "Usage: ./p (halt|restart|phased-restart|start|stats|status|stop|reload-worker-directory|gc|gc-stats)"
exit
end
case arg
when 'start'
if `pumactl -C tcp://127.0.0.1:9293 --control-token #{token} status`.start_with?("Puma is started")
puts "Puma is already running"
else
puts `puma --control tcp://127.0.0.1:9293 --control-token #{token} -d`
end
else
if `pumactl -C tcp://127.0.0.1:9293 --control-token #{token} status`.start_with?("Connection refused")
puts "Puma is not started"
else
puts `pumactl -C tcp://127.0.0.1:9293 --control-token #{token} #{arg}`
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment