Skip to content

Instantly share code, notes, and snippets.

Created May 29, 2011 14:52
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save anonymous/997829 to your computer and use it in GitHub Desktop.
Init Script to Start Django+FastCGI Server
#!/bin/sh
PATH=/sbin:/bin:/usr/sbin:/usr/bin
FCGIHOST="127.0.0.1"
FCGIPORT="5000"
RUNAS="projectuser:projectgroup"
UMASK="200"
DAEMON="/path/to/django/manage.py"
NAME="MyProject"
DESC="My Django Project"
RUNDIR=/var/run/$NAME
PIDFILE=/var/run/$NAME/$NAME.pid
ENV="env -i LANG=C PATH=/usr/local/bin:/usr/bin:/bin"
SSD="/sbin/start-stop-daemon"
DAEMON_OPTS="runfcgi host=$FCGIHOST port=$FCGIPORT pidfile=$PIDFILE daemonize=true"
test -x $DAEMON || exit 0
set -e
. /lib/lsb/init-functions
# Set up /var/run directory to write out pidfile
mkdir -p "$RUNDIR"
chown "$RUNAS" "$RUNDIR"
chmod 775 "$RUNDIR"
case "$1" in
start)
log_daemon_msg "Starting $DESC" $NAME
if ! start-stop-daemon --start --quiet --oknodo \
--pidfile $PIDFILE --umask "$UMASK" --chuid "$RUNAS" \
--exec $DAEMON -- $DAEMON_OPTS
then
log_end_msg 1
else
chmod 400 $PIDFILE
log_end_msg 0
fi
;;
stop)
log_daemon_msg "Stopping $DESC" $NAME
if [ -f $PIDFILE ]; then
kill `cat -- $PIDFILE`
rm -f -- $PIDFILE
log_end_msg 0
fi
;;
restart|force-reload)
$0 stop
$0 start
;;
status)
status_of_proc -p "$PIDFILE" "$DAEMON" "$NAME" && exit 0 || exit $?
;;
*)
echo "Usage: $0 {start|stop|restart|force-reload|status}" >&2
exit 1
;;
esac
exit 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment