Created
June 19, 2011 12:07
-
-
Save slok/1034202 to your computer and use it in GitHub Desktop.
This script executes the uwsgi command needed to deploy the Django app for example for Nginx.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# uwsgi.sh: This script executes the uwsgi command needed to deploy the Django app for example for Nginx. | |
# The only things needed that have to be changed are the PYTHON_PATH and WSGI_CONF_NAME variables | |
# NOTE: The script must be inside the Django project(root folder) | |
# | |
# Author: Xabier Larrakoetxea (slok) <slok69@gmail.com> | |
# | |
# License: This script is in public domain. | |
#MODIFY THIS! | |
PYTHON_PATH=/var/www/nginx | |
WSGI_CONF_NAME=django.wsgi | |
#Get the current dir name (last part) | |
CURRENT_DIR=$(pwd) | |
SCRIPT_DIR=$(dirname $0) | |
if [ $SCRIPT_DIR = '.' ] | |
then | |
SCRIPT_DIR="$CURRENT_DIR" | |
fi | |
SCRIPT_DIR=`basename $SCRIPT_DIR` | |
#SCRIPT_DIR=${SCRIPT_DIR##*/} | |
#Used variables | |
NAME=$SCRIPT_DIR | |
SOCKET=/tmp/uwsgi-$NAME.sock | |
PROJECT_DIR=$PYTHON_PATH/$NAME | |
WSGI_FILE=$PROJECT_DIR/$WSGI_CONF_NAME | |
PID=/tmp/uwsgi-$NAME.pid | |
LOG_FILE=/tmp/uwsgi-$NAME.log | |
#command | |
uwsgi --chdir $PROJECT_DIR \ | |
--processes 1 \ | |
--chmod-socket \ | |
--socket $SOCKET \ | |
--wsgi-file $WSGI_FILE \ | |
--pythonpath $PYTHON_PATH \ | |
--pidfile $PID \ | |
--daemonize $LOG_FILE \ | |
--harakiri 20 \ | |
--master \ | |
--vacuum \ | |
--max-requests=5000 \ | |
--memory-report \ | |
--sharedarea 4 | |
#--limit-as=128 \ | |
#--module='django.core.handlers.wsgi:WSGIHandler()' \ #We don't need if we had wsgi config file | |
#--env DJANGO_SETTINGS_MODULE=settings \ #We don't need if we had wsgi config file | |
#--home=/path/to/virtual/env \ # optionnal path to a virtualenv | |
echo "--------------------------------------" | |
echo "UWSGI STARTED FOR $NAME DJANGO PROJECT" | |
echo "" | |
echo "Socket path: $SOCKET" | |
echo "Log path: $LOG_FILE" | |
echo "PID: `cat $PID`" | |
echo "" | |
<<EXPLANATION | |
uwsgi --chdir $PROJECT_DIR \ #Change dir before startint uwsgi | |
--processes 5 \ # number of worker processes | |
--chmod-socket \ # set socket to 666 | |
--sharedarea 4 \ # create a shared memory area of 4 pages | |
--memory-report \ # enable memory usage report | |
--socket $SOCKET \ # the new openned socket | |
--wsgi-file $WSGI_FILE \ # conf wsgi file | |
--pythonpath $PYTHON_PATH \ # add the to PYTHONPATH | |
--master \ # enable master process manager | |
--pidfile $PID \ # Our PID number (file) | |
--daemonize $LOG_FILE # we want to run as a Daemon (Log file) | |
--harakiri 20 \ # respawn processes taking more than 20 seconds | |
--vacuum \ # clear environment on exit | |
--limit-as=128 \ # limit the project to 128 Megabytes | |
--max-requests=5000 # respawn processes after serving 5000 requests | |
#--module='django.core.handlers.wsgi:WSGIHandler()' \ #We don't need if we had wsgi config file | |
#--env DJANGO_SETTINGS_MODULE=settings \ #We don't need if we had wsgi config file | |
#--home=/path/to/virtual/env \ # optionnal path to a virtualenv | |
EXPLANATION |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment