Django FastCGI init.d script for Gentoo Linux

If you're not using Gentoo Linux and for more information about FastCGI/init.d go back to Django FastCGI init.d script for Linux

The initialisation script

This version uses TCP connections. I'm working on a socket-version too.

#!/sbin/runscript                                                     

DJANGO_SITES="site1 site2 site3"
SITES_PATH=/var/django/sites 
RUNFILES_PATH=/var/django/run
HOST=127.0.0.1               
PORT_START=3000              

start() {
        ebegin "Starting django-fgci"
        PORT=$PORT_START             
        for SITE in $DJANGO_SITES    
        do                           
                VERBOSE_NAME="$SITE $HOST:$PORT"
                if [ -f $RUNFILES_PATH/$SITE.pid ]; then
                        ewarn "$VERBOSE_NAME already running ($RUNFILES_PATH/$SITE.pid)"
                else
                        start-stop-daemon --start \
                                --pidfile $RUNFILES_PATH/$SITE.pid \
                                --exec /usr/bin/env python \
                                $SITES_PATH/$SITE/manage.py runfcgi \
                                method=threaded \
                                host=$HOST port=$PORT pidfile=$RUNFILES_PATH/$SITE.pid
                        chmod 400 $RUNFILES_PATH/$SITE.pid
                        einfo "$VERBOSE_NAME started"
                fi
                let "PORT = $PORT + 1"
        done
        eend $?
}

stop() {
        ebegin "Stopping django-fgci"
        for SITE in $DJANGO_SITES
        do
                VERBOSE_NAME="$SITE"
                start-stop-daemon --stop \
                         --pidfile $RUNFILES_PATH/$SITE.pid \
                        && einfo "$VERBOSE_NAME stopped" \
                        || ewarn "$VERBOSE_NAME not running"
                if [ -f $RUNFILES_PATH/$SITE.pid ]; then
                        rm $RUNFILES_PATH/$SITE.pid
                fi
        done
        eend $?
}

Note: If the init script appears to start successfully, but the FastCGI process is not started, try appending the --oknodo argument to start-stop-daemon.

Last modified 13 years ago Last modified on Jun 14, 2011, 7:13:33 AM
Note: See TracWiki for help on using the wiki.
Back to Top