Skip to content

Instantly share code, notes, and snippets.

@pirafrank
Forked from runlevel5/puma.sh
Last active August 29, 2015 14:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pirafrank/ea64dfbaceca755c3891 to your computer and use it in GitHub Desktop.
Save pirafrank/ea64dfbaceca755c3891 to your computer and use it in GitHub Desktop.
Puma manager script for your Rails application
#!/usr/bin/env bash
# This software is given AS IS, WITHOUT ANY WARRANTY.
# Simple move this file into your Rails `script` folder. Also make sure you `chmod +x puma.sh`.
# Please modify the CONSTANT variables to fit your configurations.
# The script will start with config set by $PUMA_CONFIG_FILE by default
# forked from joneslee85 https://gist.github.com/joneslee85/5844933
# edited by pirafrank https://gist.github.com/pirafrank/ea64dfbaceca755c3891
PUMA_CONFIG_FILE=config/puma.rb
PUMA_PID_FILE=tmp/pids/puma.pid
PUMA_SOCKET=/tmp/myrailsapp.sock # <-- EDIT THIS
SCRIPT_PATH=/usr/local/bin
cd /path/to/myrailsapp # <-- EDIT THIS (e.g. cd /var/www/myrailsapp)
# check if puma process is running
puma_is_running() {
if [ -S $PUMA_SOCKET ] ; then
if [ -e $PUMA_PID_FILE ] ; then
if cat $PUMA_PID_FILE | xargs pgrep -P > /dev/null ; then
return 0
else
echo "No puma process found"
fi
else
echo "No puma pid file found"
fi
else
echo "No puma socket found"
fi
return 1
}
case "$1" in
start)
echo "Starting puma..."
rm -f $PUMA_SOCKET
if [ -e $PUMA_CONFIG_FILE ] ; then
bundle exec puma --config $PUMA_CONFIG_FILE
else
bundle exec puma --daemon --bind unix://$PUMA_SOCKET --pidfile $PUMA_PID_FILE
fi
echo "done"
;;
stop)
echo "Stopping puma..."
kill -s SIGTERM `cat $PUMA_PID_FILE`
rm -f $PUMA_PID_FILE
rm -f $PUMA_SOCKET
echo "done"
;;
restart)
if puma_is_running ; then
echo "Hot-restarting puma..."
#kill -s SIGUSR2 `cat $PUMA_PID_FILE`
/bin/bash --login -c " kill -s SIGUSR2 `cat $PUMA_PID_FILE` " # patch of line above
echo "Doublechecking the process restart..."
sleep 5
if puma_is_running ; then
echo "done"
exit 0
else
echo "Puma restart failed :/"
fi
fi
echo "Trying cold reboot"
$SCRIPT_PATH/pumascript start
;;
*)
echo "Usage: pumascript {start|stop|restart}" >&2
;;
esac
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment