Init Script to Start Django+FastCGI Server
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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