-
-
Save JohnSpeno/3a20e8e6d0e9b3cc821f 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/sh | |
# | |
# gunicorn_sr Startup script for gunicorn for sr | |
# | |
# chkconfig: - 86 14 | |
# processname: gunicorn | |
# pidfile: | |
# description: Python application server | |
# | |
### BEGIN INIT INFO | |
# Provides: gunicorn_sr | |
# Required-Start: $local_fs $remote_fs $network | |
# Required-Stop: $local_fs $remote_fs $network | |
# Default-Start: 3 | |
# Default-Stop: 0 1 2 4 5 6 | |
# Short-Description: start and stop gunicorn | |
### END INIT INFO | |
# Source function library. | |
. /etc/rc.d/init.d/functions | |
prog=gunicorn | |
APP_ROOT=/PATH/TO/APP | |
UNICORN_CONF=$APP_ROOT/gunicorn.py | |
lockfile=${LOCKFILE-/var/lock/subsys/gunicorn} | |
pidfile=/var/run/gunicorn_sr.pid | |
pidfile_old=${pidfile}.oldbin | |
RETVAL=0 | |
ENV=production | |
start() { | |
echo -n $"Starting $prog: " | |
cd $APP_ROOT | |
. /PATH/TO/YOUR/VIRTUALENV/bin/activate | |
gunicorn --config $UNICORN_CONF --pid $pidfile --daemon --paste ${ENV}.ini | |
RETVAL=$? | |
echo -n | |
[ $RETVAL = 0 ] && echo -e '[\e[32m OK \e[m]' | |
[ $RETVAL = 0 ] && touch ${lockfile} | |
return $RETVAL | |
} | |
stop() { | |
echo -n $"Stopping $prog: " | |
killproc -p ${pidfile} ${prog} -QUIT | |
RETVAL=$? | |
echo | |
[ $RETVAL = 0 ] && rm -f ${lockfile} ${pidfile} | |
} | |
restart() { | |
echo -n $"Restarting $prog: " | |
killproc -p ${pidfile} ${prog} -USR2 | |
RETVAL=$? | |
echo | |
echo -n $"Stopping old $prog: " | |
killproc -p ${pidfile_old} ${prog} -QUIT | |
RETVAL=$? | |
echo | |
} | |
reload() { | |
echo -n $"Reloading $prog: " | |
killproc -p ${pidfile} ${prog} -HUP | |
RETVAL=$? | |
echo | |
} | |
rh_status() { | |
status -p ${pidfile} ${prog} | |
} | |
# See how we were called. | |
case "$1" in | |
start) | |
rh_status >/dev/null 2>&1 && exit 0 | |
start | |
;; | |
stop) | |
stop | |
;; | |
restart) | |
restart | |
;; | |
reload) | |
reload | |
;; | |
condrestart|try-restart) | |
if rh_status >/dev/null 2>&1; then | |
stop | |
start | |
fi | |
;; | |
status) | |
rh_status | |
RETVAL=$? | |
;; | |
*) | |
echo $"Usage: $prog {start|stop|restart|reload|condrestart|try-restart|status|help}" | |
RETVAL=2 | |
esac | |
exit $RETVAL |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment