Hi,
For my convenience I've written an init.d script that automatizes the
startup of my FastCGI django servers. As it might interest other
people, I share it here. Feedback is welcomed.
I can put as many sites as I want, and it will automatically assign
different port numbers to different servers in an increasing order
starting from $PORT_START. It follows the start stop restart
force-reload syntax of the startup scripts and integrates with the
startup process in Ubuntu and Debian systems. Should work in RedHat as
well, not in Gentoo though.
http://www.guindilla.eu/blog/2007/01/12/djangos-fastcgi-initd-script-linux/
The wrapper (/www/run/django_fcgi in my system) is here:
*
#! /bin/sh
[ $# = 4 ] || echo -n "Usage: $0 django_site ip port pid_file"
DJANGO_SITE=$1
IP=$2
PORT=$3
PID_FILE=$4
/usr/bin/env python $DJANGO_SITE/manage.py runfcgi \
host=$HOST port=$PORT pidfile=$PID_FILE
*
The init script is here:
*
#! /bin/sh
### BEGIN INIT INFO
# Provides: FastCGI servers for Django
# Required-Start:networking
# Required-Stop: networking
# Default-Start: 2 3 4 5
# Default-Stop: S 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
# <[EMAIL PROTECTED]>.
#
# Version: @(#)fastcgi 0.1 11-Jan-2007 [EMAIL PROTECTED]
#
SERVER SPECIFIC CONFIGURATION
#HOST=`/sbin/ifconfig | /bin/sed -n -e 's/\(.*\)inet addr:\(.*\)B.*$/\2/p'`
DJANGO_SITES="complu_haruki_eu www_haruki_eu www_guindilla_eu"
SITES_PATH=/www
DAEMON=/www/run/django_fcgi
RUNFILES_PATH=$SITES_PATH/run
HOST=127.0.0.1
PORT_START=3000
DO NOT CHANGE ANYTHING AFTER THIS LINE!
set -e
PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
DESC="FastCGI servers"
NAME=$0
SCRIPTNAME=/etc/init.d/$NAME
# Gracefully exit if the package has been removed.
test -x $DAEMON || exit 0
#
# Function that starts the daemon/service.
#
d_start()
{
# Starting all Django FastCGI processes
PORT=$PORT_START
for SITE in $DJANGO_SITES
do
echo -n ", $SITE"
# As $DAEMON is a shell script, the process runs with the name "bash",
# not "$DAEMON".
# Thus I can not use the start-stop-daemon method here.
# start-stop-daemon --start --quiet --pidfile $RUNFILES_PATH/$SITE.pid \
# --exec $DAEMON -- $SITES_PATH/$SITE $HOST $PORT
$RUNFILES_PATH/$SITE.pid \
if [ -f $RUNFILES_PATH/$SITE.pid ]; then
echo -n " already running"
else
$DAEMON $SITES_PATH/$SITE $HOST $PORT $RUNFILES_PATH/$SITE.pid
fi
let "PORT = $PORT + 1"
done
}
#
# Function that stops the daemon/service.
#
d_stop() {
# Killing all Django FastCGI processes running
for SITE in $DJANGO_SITES
do
echo -n ", $SITE"
start-stop-daemon --stop --quiet --pidfile $RUNFILES_PATH/$SITE.pid \
|| echo -n " not running"
if [ -f $RUNFILES_PATH/$SITE.pid ]; then
rm $RUNFILES_PATH/$SITE.pid
fi
done
}
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
*
Hope it helps,
G
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---