Skip to content

Instantly share code, notes, and snippets.

@TimFletcher
Created September 21, 2010 01:43

Revisions

  1. TimFletcher created this gist Sep 21, 2010.
    54 changes: 54 additions & 0 deletions run_gunicorn.sh
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,54 @@
    #!/bin/sh

    # You must have your virtualenv activated to run this script

    NAME=gunicorn_timothyfletcher
    PID=/home/fire/www/timothyfletcher.com/conf/gunicorn.pid
    SETTINGS=/home/fire/www/timothyfletcher.com/timothyfletcher/settings.py
    LOGFILE=/home/fire/www/timothyfletcher.com/logs/gunicorn.log
    WORKERS=8
    BIND_ADDRESS=127.0.0.1:8000

    RETVAL=0

    start()
    {
    echo "Starting $NAME..."
    gunicorn_django --name $NAME --pid $PID --workers=$WORKERS --bind=$BIND_ADDRESS --log-file=$LOGFILE --daemon $SETTINGS && echo "Gunicorn started" || echo "Failed";
    }

    stop()
    {
    echo "Stopping $NAME with PID `cat $PID`..."
    kill -QUIT `cat $PID` && echo "Gunicorn stopped" || echo "Failed";
    }

    reload()
    {
    echo "Reloading $NAME..."
    if [ -f $PID ]
    then kill -HUP `cat $PID` && echo "Gunicorn reloaded" || echo "Failed";
    fi
    }

    case "$1" in
    start)
    start
    ;;
    stop)
    stop
    ;;
    restart)
    reload
    ;;
    reload)
    reload
    ;;
    force-reload)
    stop && start
    ;;
    *)
    echo $"Usage: $0 {start|stop|restart}"
    RETVAL=1
    esac
    exit $RETVAL