shameless stolen from https://gist.github.com/joneslee85/5844933
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
#please check the paths for your app | |
BASE_FOLDER=/home/www/TestProject | |
PUMA_CONFIG_FILE=$BASE_FOLDER/config/puma.rb | |
#chante to your project folder | |
cd $BASE_FOLDER | |
#source file for rvm jruby | |
source /usr/local/rvm/environments/jruby-1.7.11 | |
# 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 | |
$BASE_FOLDER/bin/puma --config $PUMA_CONFIG_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` | |
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/puma.sh start | |
;; | |
*) | |
echo "Usage: script/puma.sh {start|stop|restart}" >&2 | |
;; | |
esac |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment