Created
July 23, 2012 07:08
-
-
Save graffic/3162377 to your computer and use it in GitHub Desktop.
Django on fastcgi and nginx featuring transifex.
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/sh | |
### BEGIN INIT INFO | |
# Provides: FastCGI servers for Django | |
# Required-Start: $network | |
# Required-Stop: $network | |
# Default-Start: 2 3 4 5 | |
# Default-Stop: 0 1 6 | |
# Short-Description: Start FastCGI servers with Django. | |
# Description: Django, in order to operate with FastCGI, must be started | |
# in a very specific way with manage.py. This must be done | |
# for each DJango web server that has to run. | |
### END INIT INFO | |
# | |
# Author: Guillermo Fernandez Castellanos | |
# <guillermo.fernandez.castellanos AT gmail.com>. | |
# | |
# Version: @(#)fastcgi 0.1 11-Jan-2007 guillermo.fernandez.castellanos AT gmail.com | |
# | |
# REFERENCES: | |
# Taken from: https://code.djangoproject.com/wiki/InitdScriptForLinux | |
#### SERVER SPECIFIC CONFIGURATION | |
ENVIRONMENT=/home/transifex/.virtualenvs/testtransifex/bin/ | |
SITE=/home/transifex/.virtualenvs/testtransifex/lib/python2.7/site-packages/transifex-1.2.1-py2.7.egg/transifex/ | |
RUNFILES_FOLDER=/var/run/django-transifex | |
RUNFILES_PATH=$RUNFILES_FOLDER/transifex | |
RUN_AS=transifex | |
FCGI_METHOD=threaded | |
#### DO NOT CHANGE ANYTHING AFTER THIS LINE! | |
set -e | |
PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin | |
DESC="Transifex FastCGI server" | |
NAME=$0 | |
SCRIPTNAME=/etc/init.d/$NAME | |
# | |
# Function that starts the daemon/service. | |
# | |
d_start() | |
{ | |
# Starting all Django FastCGI processes | |
if [ -f ${RUNFILES_PATH}.pid ]; then | |
echo " already running" | |
else | |
mkdir -p $RUNFILES_FOLDER | |
chown transifex:transifex $RUNFILES_FOLDER | |
start-stop-daemon --start --quiet \ | |
--pidfile ${RUNFILES_PATH}.pid \ | |
--chuid $RUN_AS --exec /usr/bin/env -- $ENVIRONMENT/python \ | |
$SITE/manage.py runfcgi \ | |
method=$FCGI_METHOD \ | |
socket=${RUNFILES_PATH}.socket \ | |
pidfile=${RUNFILES_PATH}.pid | |
chmod 400 ${RUNFILES_PATH}.pid | |
chmod g+w ${RUNFILES_PATH}.socket | |
fi | |
} | |
# | |
# Function that stops the daemon/service. | |
# | |
d_stop() { | |
# Killing all Django FastCGI processes running | |
start-stop-daemon --stop --quiet --pidfile ${RUNFILES_PATH}.pid \ | |
|| echo " not running" | |
if [ -f ${RUNFILES_PATH}.pid ]; then | |
rm ${RUNFILES_PATH}.pid | |
fi | |
} | |
ACTION="$1" | |
case "$ACTION" in | |
start) | |
echo -n "Starting $DESC: $NAME" | |
d_start | |
echo "." | |
;; | |
stop) | |
echo -n "Stopping $DESC: $NAME" | |
d_stop | |
echo "." | |
;; | |
restart|force-reload) | |
echo -n "Restarting $DESC: $NAME" | |
d_stop | |
sleep 1 | |
d_start | |
echo "." | |
;; | |
*) | |
echo "Usage: $NAME {start|stop|restart|force-reload}" >&2 | |
exit 3 | |
;; | |
esac | |
exit 0 |
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
# Nginx configuration snippet | |
server { | |
listen 80; | |
server_name transifex; | |
location ~ /\.ht { | |
deny all; | |
} | |
location ~ \.svn { | |
deny all; | |
} | |
log_not_found off; | |
server_name_in_redirect off; | |
location / { | |
# First attempt to serve request as file, then | |
# as directory, then fall back to index.html | |
#try_files $uri $uri/ /index.html; | |
# Uncomment to enable naxsi on this location | |
# include /etc/nginx/naxsi.rules | |
fastcgi_param PATH_INFO $fastcgi_script_name; | |
fastcgi_param REQUEST_METHOD $request_method; | |
fastcgi_param QUERY_STRING $query_string; | |
fastcgi_param SERVER_NAME $server_name; | |
fastcgi_param SERVER_PORT $server_port; | |
fastcgi_param SERVER_PROTOCOL $server_protocol; | |
fastcgi_param CONTENT_TYPE $content_type; | |
fastcgi_param CONTENT_LENGTH $content_length; | |
fastcgi_pass_header Authorization; | |
fastcgi_intercept_errors off; | |
fastcgi_pass unix:/var/run/django-transifex/transifex.socket; | |
fastcgi_read_timeout 300s; | |
fastcgi_send_timeout 300s; | |
} | |
location /site_media { | |
root /home/transifex/.virtualenvs/testtransifex/lib/python2.7/site-packages/transifex-1.2.1-py2.7.egg/transifex; | |
location ~* \.(jpg|jpeg|gif|css|png|js|ico|html)$ { | |
expires max; | |
access_log off; | |
} | |
} | |
location /media { | |
root /home/transifex/.virtualenvs/testtransifex/lib/python2.7/site-packages/Django-1.3.1-py2.7.egg/django/contrib; | |
location ~* \.(jpg|jpeg|gif|css|png|js|ico|html)$ { | |
expires max; | |
access_log off; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment