-
-
Save jrheling/7f23b87826a6fd923d25c1ec550bbdc1 to your computer and use it in GitHub Desktop.
gunicorn virtualenv init.d script (could be simpler with upstart)
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 | |
### BEGIN INIT INFO | |
# Provides: YOURAPP | |
# Required-Start: nginx | |
# Required-Stop: | |
# Default-Start: 2 3 4 5 | |
# Default-Stop: 0 1 6 | |
# Short-Description: The main gunicorn process for YOURAPP | |
# Description: The gunicorn process that receives HTTP requests | |
# from nginx and proxies them to YOURAPP. | |
# | |
### END INIT INFO | |
# | |
# Author: mle <[email protected]> | |
# (modified by jrheling <[email protected]>) | |
# | |
## customize these for your environment / application | |
APPNAME=yourapp | |
USER=YOURUSER | |
ACTIVATE=/PATH/TO/virtualenvs/VENVNAME/bin/activate | |
RUNDIR=/PATH/TO/APPDIR | |
APPMODULE=yourapp:app | |
## shouldn't need to modify these | |
PATH=/bin:/usr/bin:/sbin:/usr/sbin | |
PROGRAM=gunicorn | |
BIND=127.0.0.1:8000 | |
PIDFILE=/var/run/gunicorn.pid | |
LOGFILE=/var/log/$APPNAME.log | |
WORKERS=2 | |
. /etc/rc.d/init.d/functions | |
if [ -e "/etc/default/$APPNAME" ] | |
then | |
. /etc/default/$APPNAME | |
fi | |
case "$1" in | |
start) | |
echo -n "Starting gunicorn instance for" "${APPNAME}: " | |
source $ACTIVATE | |
cd $RUNDIR | |
daemon $PROGRAM --daemon --bind=$BIND --pid=$PIDFILE --workers=$WORKERS --user=$USER --log-file=$LOGFILE $APPMODULE | |
#echo $? | |
echo | |
;; | |
stop) | |
echo -n "Stopping gunicorn instance for" "${APPNAME}: " | |
killproc -p $PIDFILE $PROGRAM | |
echo | |
;; | |
force-reload|restart) | |
$0 stop | |
$0 start | |
;; | |
status) | |
status -p $PIDFILE $PROGRAM && exit 0 || exit $? | |
;; | |
*) | |
echo "Usage: /etc/init.d/$APPNAME {start|stop|restart|force-reload|status}" | |
exit 1 | |
;; | |
esac | |
exit 0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment