Skip to content

Instantly share code, notes, and snippets.

@thunder-spb
Created September 3, 2015 11:06
Show Gist options
  • Save thunder-spb/42b41faeb4a2f1dc08c7 to your computer and use it in GitHub Desktop.
Save thunder-spb/42b41faeb4a2f1dc08c7 to your computer and use it in GitHub Desktop.

Revisions

  1. thunder-spb created this gist Sep 3, 2015.
    34 changes: 34 additions & 0 deletions gunicorn_start
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,34 @@
    #!/bin/bash

    NAME="app_newretail" # Name of the application
    DJANGODIR=/data/webapps/python/newretail/${NAME} # Django project directory
    SOCKFILE=/data/webapps/python/newretail/run/gunicorn.sock # we will communicte using this unix socket
    USER=py_webapps # the user to run as
    GROUP=webapps # the group to run as
    NUM_WORKERS=3 # how many worker processes should Gunicorn spawn
    DJANGO_SETTINGS_MODULE=${NAME}.settings # which settings file should Django use
    DJANGO_WSGI_MODULE=${NAME}.wsgi # WSGI module name

    echo "Starting $NAME as `whoami`"

    # Activate the virtual environment
    cd $DJANGODIR
    source ../bin/activate
    export DJANGO_SETTINGS_MODULE=$DJANGO_SETTINGS_MODULE
    export PYTHONPATH=$DJANGODIR:$PYTHONPATH

    # Create the run directory if it doesn't exist
    RUNDIR=$(dirname $SOCKFILE)
    test -d $RUNDIR || mkdir -p $RUNDIR

    # Start your Django Unicorn
    # Programs meant to be run under supervisor should not daemonize themselves (do not use --daemon)
    exec ../bin/gunicorn ${DJANGO_WSGI_MODULE}:application \
    --name $NAME \
    --workers $NUM_WORKERS \
    --user=$USER --group=$GROUP \
    --bind=unix:$SOCKFILE \
    --reload \
    --timeout=300 \
    --log-level=info \
    --log-file=-