Skip to content

Instantly share code, notes, and snippets.

@oinopion
Created December 15, 2011 11:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save oinopion/1480809 to your computer and use it in GitHub Desktop.
Save oinopion/1480809 to your computer and use it in GitHub Desktop.
Simple wrapper (used mostly in supervisord)
#!/bin/bash
# This script is a wrapper around gunicorn
# It provides clean interface for starting stopping app server
PROJECT_NAME=photon
HOME_DIR=/home/photon
RELEASE_DIR=$HOME_DIR/releases/current
GUNICORN_BIN=$HOME_DIR/bin/gunicorn_django
GUNICORN_PID=$HOME_DIR/pids/gunicorn.pid
GUNICORN_CONF=$RELEASE_DIR/config/gunicorn.conf.py
DJANGO_SETTINGS=$RELEASE_DIR/$PROJECT_NAME/production.py
# activate virtualenv environment
source $HOME_DIR/bin/activate
function start {
echo "Starting gunicorn.";
ulimit -s 512;
exec $GUNICORN_BIN --config $GUNICORN_CONF $DJANGO_SETTINGS;
}
function stop {
echo "Stopping gunicorn.";
kill `cat $GUNICORN_PID`;
}
function reload {
echo "Reloading gunicorn workers.";
kill -HUP `cat $GUNICORN_PID`;
}
function add_worker {
echo "Adding one worker."
kill -TTIN `cat $GUNICORN_PID`;
}
function remove_worker {
echo "Removing one worker."
kill -TTOU `cat $GUNICORN_PID`;
}
case $1 in
"start") start;;
"stop") stop;;
"reload") reload;;
"add_worker") add_worker;;
"remove_worker") remove_worker;;
*) echo "No argument given: start|stop|reload|add_worker|remove_worker";;
esac
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment