Created
February 12, 2015 09:15
-
-
Save catatsuy/b6edf72f518d45283ee4 to your computer and use it in GitHub Desktop.
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/bash | |
PATH=/usr/local/rbenv/shims:/usr/local/rbenv/bin:/usr/local/bin:/bin:/usr/bin:/sbin:/usr/sbin | |
NAME=unicorn | |
RAILS_ENV=${RAILS_ENV:-production} | |
APP=application_name | |
EX_USER=www-data | |
ROOT_DIR="/home/$USER/$APP/current" | |
PID="${ROOT_DIR}/tmp/pids/unicorn.pid" | |
CONF="${ROOT_DIR}/config/unicorn/${RAILS_ENV}.rb" | |
if test "$USER" != "$EX_USER"; then | |
echo "please execute by $EX_USER user !!" | |
exit 1 | |
fi | |
start() { | |
cd $ROOT_DIR | |
if test -e $PID && pgrep -F $PID > /dev/null; then | |
echo "$NAME already started"; | |
exit 1; | |
fi | |
echo "start $NAME"; | |
BUNDLE_GEMFILE="${ROOT_DIR}/Gemfile" bundle exec unicorn_rails -c ${CONF} -E ${RAILS_ENV} -D | |
} | |
stop() { | |
if ! ( test -e $PID && pgrep -F $PID > /dev/null ); then | |
echo "$NAME not started"; | |
exit 1; | |
fi | |
echo "stop $NAME"; | |
kill `cat ${PID}` | |
rm -f $PID | |
} | |
graceful_stop() { | |
if ! ( test -e $PID && pgrep -F $PID > /dev/null ); then | |
echo "$NAME not started"; | |
exit 1; | |
fi | |
echo "stop $NAME"; | |
kill -QUIT `cat ${PID}` | |
rm -f $PID | |
} | |
reload() { | |
if ! ( test -e $PID && pgrep -F $PID > /dev/null ); then | |
echo "$NAME not started"; | |
start | |
exit 0; | |
fi | |
echo "reload $NAME"; | |
kill -USR2 `cat ${PID}` | |
} | |
restart() { | |
if ! ( test -e $PID && pgrep -F $PID > /dev/null ); then | |
echo "$NAME not started"; | |
start | |
exit 0; | |
fi | |
echo "restart $NAME"; | |
graceful_stop | |
start | |
} | |
case "$1" in | |
start) | |
start | |
;; | |
stop) | |
graceful_stop | |
;; | |
force_stop) | |
stop | |
;; | |
reload) | |
reload | |
;; | |
restart) | |
restart | |
;; | |
*) | |
echo "Syntax Error: check [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