Skip to content

Instantly share code, notes, and snippets.

@whalesalad
Created August 11, 2009 11:09
Show Gist options
  • Select an option

  • Save whalesalad/165743 to your computer and use it in GitHub Desktop.

Select an option

Save whalesalad/165743 to your computer and use it in GitHub Desktop.
#! /bin/bash
# Author: Guillermo Fernandez Castellanos
# <guillermo.fernandez.castellanos AT gmail.com>
#
# Altered by David Reynolds for Debian Stable <david AT reynoldsfamily.org.uk>
# Further altered by Michael Whalen <michael at whalesalad.com>
#
# In this example, my django projects are stored in /usr/local
# one is named siteone and the other is named sitetwo.
#
# I previously used to get the "let: command not exist" type of error with this
# script, so I fixed it.
#### SERVER SPECIFIC CONFIGURATION
#export PYTHONPATH=/var/www/django/trunk/:/var/www/django/
DJANGO_SITES="siteone sitetwo"
SITES_PATH=/usr/local
RUNFILES_PATH=/var/run/fastcgi
HOST=127.0.0.1
PORT_START=3033
RUN_AS=www-data
#### 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
#
# 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"
if [ -f $RUNFILES_PATH/$SITE.pid ]; then
echo -n " already running"
else
start-stop-daemon --start \
--exec /usr/bin/python $SITES_PATH/$SITE/manage.py runfcgi method=threaded \
host=$HOST port=$PORT pidfile=$RUNFILES_PATH/$SITE.pid --pidfile $RUNFILES_PATH/$SITE.pid
chmod 400 $RUNFILES_PATH/$SITE.pid
fi
let PORT++
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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment