Skip to content

Instantly share code, notes, and snippets.

@igaiga
Last active January 1, 2016 16:08
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 igaiga/8168352 to your computer and use it in GitHub Desktop.
Save igaiga/8168352 to your computer and use it in GitHub Desktop.
#!/bin/sh
# refered to http://shoprev.hatenablog.com/entry/2013/07/15/172404 . thanks!
NAME="Unicorn for tdiary"
ROOT_DIR="/home/igarashi/var/tdiary/tdiary-core"
PID="${ROOT_DIR}/unicorn.pid"
CONF="${ROOT_DIR}/unicorn.conf"
BUNDLE_DIR="/home/igarashi/.rbenv/shims/"
CMD="${BUNDLE_DIR}/bundle exec unicorn -c ${CONF} -D"
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