Ticket #11578: django-init-d.patch

File django-init-d.patch, 5.0 KB (added by basti, 6 years ago)
  • extras/django_etc_default

     
     1# django project names/directories
     2DJANGO_SITES="myapp myapp2 myapp3"
     3
     4# path to the directory with your django projects
     5#SITES_PATH=/home/django/projects
     6
     7# path to the directory for socket and pid files
     8RUNFILES_PATH=$SITES_PATH/run
     9
     10# please make sure this is NOT root
     11# local user prefered, www-data accepted
     12RUN_AS=django
     13
     14# maximum requests before fast-cgi process respawns
     15# (a.k.a. get killed and let live)
     16MAXREQUESTS=100
  • extras/django_init_d

    Property changes on: extras/django_etc_default
    ___________________________________________________________________
    Added: svn:executable
       + *
    
     
     1#! /bin/sh
     2### BEGIN INIT INFO
     3# Provides:          FastCGI servers for Django
     4# Required-Start:    networking
     5# Required-Stop:     networking
     6# Default-Start:     2 3 4 5
     7# Default-Stop:      S 0 1 6
     8# Short-Description: Start FastCGI servers with Django.
     9# Description:       Django, in order to operate with FastCGI, must be started
     10#                    in a very specific way with manage.py. This must be done
     11#                    for each Django web server that has to run.
     12### END INIT INFO
     13#
     14# Author:  Guillermo Fernandez Castellanos
     15#          <guillermo.fernandez.castellanos AT gmail.com>.
     16#
     17# Changed: Jannis Leidel
     18#          <jannis AT leidel.info>
     19#          Joost Cassee
     20#          <joost@cassee.net>
     21#          Sebastian Rahlf
     22#          <basti AT redtoad.de>
     23#
     24# Version: @(#)fastcgi 0.4 28-Jul-2009 basti AT redtoad.de
     25#
     26
     27set -e
     28
     29#### CONFIGURATION (override in /etc/default/django)
     30
     31# django project names/directories
     32DJANGO_SITES=""
     33
     34# path to the directory with your django projects
     35SITES_PATH=/var/lib/django
     36
     37# path to the directory for socket and pid files
     38RUNFILES_PATH=/var/run/django
     39
     40# please make sure this is NOT root
     41# local user prefered, www-data accepted
     42RUN_AS=www-data
     43
     44# maximum requests before fast-cgi process respawns
     45# (a.k.a. get killed and let live)
     46MAXREQUESTS=1000
     47
     48#### END CONFIGURATION
     49
     50# Include defaults if available
     51if [ -f /etc/default/django ] ; then
     52    . /etc/default/django
     53fi
     54
     55PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
     56DESC="Django FastCGI servers"
     57NAME=$0
     58SCRIPTNAME=/etc/init.d/$NAME
     59mkdir -p $RUNFILES_PATH
     60chown -R $RUN_AS:$RUN_AS $RUNFILES_PATH
     61
     62# A specific site can be started/stopped by appending its name
     63SITE=$2
     64if [ -n "$SITE" ]; then
     65    DJANGO_SITES=$SITE
     66fi
     67
     68#
     69#       Function that starts the daemon/service.
     70#
     71d_start()
     72{
     73    # Starting all Django FastCGI processes
     74    # PORT=$PORT_START
     75    for SITE in $DJANGO_SITES
     76    do
     77        echo -n " $SITE"
     78        if [ -f $RUNFILES_PATH/$SITE.pid ]; then
     79            echo -n " already running"
     80        else
     81            start-stop-daemon --start --quiet \
     82                --pidfile $RUNFILES_PATH/$SITE.pid \
     83                --chuid $RUN_AS --exec /usr/bin/env -- python \
     84                $SITES_PATH/$SITE/manage.py runfcgi \
     85                    protocol=fcgi method=threaded \
     86                    maxrequests=$MAXREQUESTS \
     87                    pidfile=$RUNFILES_PATH/$SITE.pid \
     88                    socket=$RUNFILES_PATH/$SITE.socket
     89            chmod 400 $RUNFILES_PATH/$SITE.pid
     90        fi
     91        sleep 1
     92    done
     93}
     94
     95#
     96#       Function that stops the daemon/service.
     97#
     98d_stop() {
     99    # Killing all Django FastCGI processes running
     100    for SITE in $DJANGO_SITES
     101    do
     102        echo -n " $SITE"
     103        start-stop-daemon --stop --quiet --pidfile $RUNFILES_PATH/$SITE.pid \
     104                          || echo -n " not running"
     105        if [ -f $RUNFILES_PATH/$SITE.pid ]; then
     106           rm -f $RUNFILES_PATH/$SITE.pid
     107        fi
     108        sleep 1
     109    done
     110}
     111
     112ACTION="$1"
     113case "$ACTION" in
     114    start)
     115        echo -n "Starting $DESC:"
     116        d_start
     117        echo "."
     118        ;;
     119
     120    stop)
     121        echo -n "Stopping $DESC:"
     122        d_stop
     123        echo "."
     124        ;;
     125
     126    status)
     127        echo "Status of $DESC:"
     128        for SITE in $DJANGO_SITES
     129        do
     130            echo -n "  $SITE"
     131            if [ -f $RUNFILES_PATH/$SITE.pid ]; then
     132                echo " running ($(cat $RUNFILES_PATH/$SITE.pid))"
     133            else
     134                echo " not running"
     135            fi
     136        done
     137        ;;
     138
     139    restart|force-reload)
     140        echo -n "Restarting $DESC: $NAME"
     141        d_stop
     142        sleep 2
     143        d_start
     144        echo "."
     145        ;;
     146
     147    *)
     148        echo "Usage: $NAME {start|stop|restart|force-reload|status} [site]" >&2
     149        exit 3
     150        ;;
     151esac
     152
     153exit 0
Back to Top