Created
January 7, 2013 02:56
-
-
Save komasaru/4471948 to your computer and use it in GitHub Desktop.
Script to start unicorn.
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
#!/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