Skip to content

Instantly share code, notes, and snippets.

@kerin
Created March 21, 2013 12:04
Show Gist options
  • Save kerin/5212541 to your computer and use it in GitHub Desktop.
Save kerin/5212541 to your computer and use it in GitHub Desktop.
#!/bin/sh
### BEGIN INIT INFO
# Provides: gunicorn-ostsite
# Required-Start: $remote_fs
# Required-Stop: $remote_fs
# Should-Start: $all
# Should-Stop: $all
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: Event-based HTTP/WSGI server (running ostsite)
# Description: Green Unicorn (gunicorn) is an HTTP/WSGI server designed
# to serve fast clients or sleepy applications. That is to
# say; behind a buffering front-end server such as nginx or
# lighttpd. This instance runs ostsite.
### END INIT INFO
NAME=gunicorn-ostsite
DESC=$NAME
VENV=/usr/local/venv/ostsite
SRC=/usr/local/ostmodern.co.uk/django
DAEMON=$VENV/bin/gunicorn_django
CHOWN="-croot:root"
SOCKET=unix:/var/run/gunicorn/ostsite.sock
RUNDIR=/var/run/gunicorn
PIDFILE=/var/run/gunicorn/ostsite.pid
LOGFILE=/var/log/gunicorn/ostsite.log
WORKERS=1
TIMEOUT=30
MODULE=
CONFFILE=""
DAEMON_OPTS="$CONFFILE -b $SOCKET -p $PIDFILE --log-file $LOGFILE \
--workers $WORKERS -t $TIMEOUT --daemon --name $NAME $MODULE"
test -x $DAEMON || exit 0
set -e
. /lib/lsb/init-functions
if [ ! -d $RUNDIR ]; then
mkdir -p $RUNDIR
chown root:root $RUNDIR
fi
case "$1" in
start)
echo -n "Starting $DESC: "
start-stop-daemon -S $CHOWN -q -p $PIDFILE -d $SRC \
-x $DAEMON -- $DAEMON_OPTS || true
echo "$NAME."
;;
stop)
echo -n "Stopping $DESC: "
start-stop-daemon -K -q -p $PIDFILE -s QUIT || true
echo "$NAME."
;;
restart)
echo -n "Restarting $DESC: "
start-stop-daemon -K -q -p $PIDFILE -s QUIT || true
sleep 1
start-stop-daemon -S $CHOWN -q -p $PIDFILE -d $SRC \
-x $DAEMON -- $DAEMON_OPTS || true
echo "$NAME."
;;
reload)
echo -n "Reloading $DESC: "
start-stop-daemon -K -q -p $PIDFILE -s HUP || true
echo "$NAME."
;;
status)
status_of_proc -p $PIDFILE "$DAEMON" $NAME && exit 0 || exit $?
;;
*)
echo "Usage: $NAME {start|stop|restart|status}" >&2
exit 1
;;
esac
exit 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment