Skip to content

Instantly share code, notes, and snippets.

@showwin
Last active May 3, 2019 13:35
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 showwin/7288aebc20b5ce189491888cc7881883 to your computer and use it in GitHub Desktop.
Save showwin/7288aebc20b5ce189491888cc7881883 to your computer and use it in GitHub Desktop.
rbenv + unicorn の init スクリプト
#!/bin/sh
#chkconfig:2345 85 70
#description:unicorn shell
NAME="Unicorn"
ENV=production
USER="root"
ROOT_DIR="/opt/rails/[PROJECT_NAME]"
APP_DIR="${ROOT_DIR}/current"
GEMFILE="${APP_DIR}/Gemfile"
CONF="${APP_DIR}/config/unicorn.rb"
PID="${ROOT_DIR}/shared/tmp/pids/unicorn.pid"
OPTIONS=""
start()
{
if [ -e $PID ]; then
echo "$NAME already started"
exit 1
fi
echo "start $NAME"
cd $ROOT_DIR
su - ${USER} -c "cd ${APP_DIR} && rbenv rehash && rbenv local `cat ${APP_DIR}/.ruby-version` && BUNDLE_GEMFILE=${GEMFILE} bundle exec unicorn -c ${CONF} -E ${ENV} -D ${OPTIONS}"
}
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}`
}
restart()
{
stop
sleep 3
start
}
case "$1" in
start)
start
;;
stop)
stop
;;
force-stop)
force_stop
;;
restart)
restart
;;
*)
echo "Syntax Error: release [start|stop|force-stop|restart]"
;;
esac
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment