Skip to content

Instantly share code, notes, and snippets.

@komasaru
Created January 7, 2013 02:56
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save komasaru/4471948 to your computer and use it in GitHub Desktop.
Save komasaru/4471948 to your computer and use it in GitHub Desktop.
Script to start unicorn.
#!/bin/sh
NAME="Unicorn"
ENV=production
ROOT_DIR="/var/www/rails/rails_app"
PID="${ROOT_DIR}/tmp/pids/unicorn.pid"
CONF="${ROOT_DIR}/config/unicorn.rb"
OPTIONS="--path /rails_app"
CMD="bundle exec unicorn_rails -c ${CONF} -E ${ENV} -D ${OPTIONS}"
start()
{
if [ -e $PID ]; then
echo "$NAME already started"
exit 1
fi
echo "start $NAME"
cd $ROOT_DIR
$CMD
}
stop()
{
if [ ! -e $PID ]; then
echo "$NAME not started"
exit 1
fi
echo "stop $NAME"
kill -QUIT `cat ${PID}`
}
force_stop()
{
if [ ! -e $PID ]; then
echo "$NAME not started"
exit 1
fi
echo "stop $NAME"
kill -INT `cat ${PID}`
}
reload()
{
if [ ! -e $PID ]; then
echo "$NAME not started"
start
exit 0
fi
echo "reload $NAME"
kill -HUP `cat ${PID}`
}
restart()
{
stop
# Unicorn が停止し切らない内に起動しようとしないように
sleep 3
start
}
case "$1" in
start)
start
;;
stop)
stop
;;
force-stop)
force_stop
;;
reload)
reload
;;
restart)
restart
;;
*)
echo "Syntax Error: release [start|stop|force-stop|reload|restart]"
;;
esac
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment