Skip to content

Instantly share code, notes, and snippets.

@omgbbqhaxx
Forked from postrational/gunicorn_start.bash
Last active December 23, 2015 17:59
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 omgbbqhaxx/6672669 to your computer and use it in GitHub Desktop.
Save omgbbqhaxx/6672669 to your computer and use it in GitHub Desktop.
#!/bin/bash
NAME="hello_app" # Name of the application
DJANGODIR=/opt/venv/retwiends # Django project directory
SOCKFILE=/opt/venv/run/gunicorn.sock # we will communicte using this unix socket
USER=root # the user to run as
GROUP=root # the group to run as
NUM_WORKERS=3 # how many worker processes should Gunicorn spawn
DJANGO_SETTINGS_MODULE=retwiends.settings # which settings file should Django use
DJANGO_WSGI_MODULE=retwiends.wsgi # WSGI module name
echo "Starting $NAME"
# 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 \
--log-level=debug \
--bind=unix:$SOCKFILE
[program:hello]
command = /opt/venv/bin/gunicorn_start ; Command to start app
user = root ; User to run as
stdout_logfile = /opt/venv/logs/gunicorn_supervisor.log ; Where to write log messages
redirect_stderr = true ; Save stderr in the same log
upstream hello_app_server {
# fail_timeout=0 means we always retry an upstream even if it failed
# to return a good HTTP response (in case the Unicorn master nukes a
# single worker for timing out).
server unix:/opt/venv/run/gunicorn.sock fail_timeout=0;
}
server {
listen 80;
server_name retwiends.com;
client_max_body_size 4G;
access_log /opt/venv/logs/nginx-access.log;
error_log /opt/venv/logs/nginx-error.log;
location /static/ {
alias /opt/venv/retwiends/retwiends/templates/static/;
}
location /media/ {
alias /opt/venv/retwiends/retwiends/templates/media/;
}
location / {
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $http_host;
proxy_redirect off;
if (!-f $request_filename) {
proxy_pass http://hello_app_server;
break;
}
}
# Error pages
error_page 500 502 503 504 /500.html;
location = /500.html {
root /opt/venv/retwiends/retwiends/templates/static/;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment