- Save puma.rb file locally (eg. to ~/bin/puma.rb)
- Create alias
alias p='~/bin/puma.rb
in bash.rc
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 |