Skip to content

Instantly share code, notes, and snippets.

@ipl31
Forked from suda/gunicorn
Created December 5, 2011 07:57

Revisions

  1. @suda suda revised this gist Dec 20, 2010. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion gunicorn
    Original file line number Diff line number Diff line change
    @@ -32,7 +32,7 @@ SERVER="$2"
    test -x $DAEMON || exit 0

    if [ -f /etc/default/gunicorn ] ; then
    . /etc/default/gunicorn
    . /etc/default/gunicorn
    fi

    if [ ! -d /var/run/gunicorn ]; then
  2. @suda suda revised this gist Dec 20, 2010. 1 changed file with 1 addition and 0 deletions.
    1 change: 1 addition & 0 deletions gunicorn
    Original file line number Diff line number Diff line change
    @@ -12,6 +12,7 @@

    # Gunicorn init.d script for debian/ubuntu
    # Written by Wojtek 'suda' Siudzinski <[email protected]>
    # Gist: https://gist.github.com/748450
    #
    # Sample config (/etc/default/gunicorn):
    #
  3. @suda suda created this gist Dec 20, 2010.
    99 changes: 99 additions & 0 deletions gunicorn
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,99 @@
    #!/bin/sh

    ### BEGIN INIT INFO
    # Provides: gunicorn
    # Required-Start: $all
    # Required-Stop: $all
    # Default-Start: 2 3 4 5
    # Default-Stop: 0 1 6
    # Short-Description: starts the gunicorn server
    # Description: starts gunicorn using start-stop-daemon
    ### END INIT INFO

    # Gunicorn init.d script for debian/ubuntu
    # Written by Wojtek 'suda' Siudzinski <[email protected]>
    #
    # Sample config (/etc/default/gunicorn):
    #
    # SERVERS=(
    # 'server_name port project_path number_of_workers'
    # )
    # RUN_AS='www-data'
    #
    # WARNING: user $RUN_AS must have +w on /var/run/gunicorn

    PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
    DAEMON=/usr/bin/gunicorn_django
    NAME=gunicorn
    DESC=gunicorn
    SERVER="$2"

    test -x $DAEMON || exit 0

    if [ -f /etc/default/gunicorn ] ; then
    . /etc/default/gunicorn
    fi

    if [ ! -d /var/run/gunicorn ]; then
    mkdir /var/run/gunicorn
    fi

    start () {
    for i in "${SERVERS[@]}"
    do
    :
    set -- "$i"
    IFS=" "; declare -a data=($*)

    if [ "$SERVER" ]; then
    if [ "$SERVER" != ${data[0]} ]; then
    continue
    fi
    fi
    echo "Spawning ${data[0]}"
    start-stop-daemon --start --pidfile /var/run/gunicorn/${data[0]}.pid -c $RUN_AS -d ${data[2]} --exec $DAEMON -- -b 127.0.0.1:${data[1]} -w ${data[3]} -D -p /var/run/gunicorn/${data[0]}.pid
    done
    return
    }

    stop () {
    for i in "${SERVERS[@]}"
    do
    :
    set -- "$i"
    IFS=" "; declare -a data=($*)
    if [ "$SERVER" ]; then
    if [ "$SERVER" != ${data[0]} ]; then
    continue
    fi
    fi
    if [ -f /var/run/gunicorn/${data[0]}.pid ]; then
    echo "Killing ${data[0]}"
    kill $(cat /var/run/gunicorn/${data[0]}.pid)
    fi
    done
    }

    case "$1" in
    start)
    echo "Starting $DESC"
    start
    ;;
    stop)
    echo "Stopping $DESC"
    stop
    ;;
    restart)
    echo "Restarting $DESC"
    stop
    sleep 1
    start
    ;;
    *)
    N=/etc/init.d/$NAME
    echo "Usage: $N {start|stop|restart} [particular_server_to_restart]" >&2
    exit 1
    ;;
    esac

    exit 0