#!/bin/bash ### BEGIN INIT INFO # Provides: spawning.debian # Required-Start: $all # Required-Stop: $all # Default-Start: 2 3 4 5 # Default-Stop: 0 1 6 # Short-Description: starts a Spawning daemon # Description: starts a Spawning daemon ### END INIT INFO # Usage instructions: # - Copy this file to your /etc/init.d directory: # $ sudo cp spawning.debian /etc/init.d/spawning.mysite # - Change the options below in the "Configuration" section. # Spawning arguments currently supported are: # - host (defaults to 127.0.0.1) # - port (defaults to 8080) # - access-log (defaults to /dev/null) # - stderr (defaults to /dev/null) # - chuid (optional) # - factory (optional) # - processes (optional) # If you have additional arguments to provide (such as # max-age, watch, workers etc., add them as follows: # EXTRA_ARGS="max-age=1000 --watch=file" etc. # - Initialise the script to survive reboots: # $ sudo update-rc.d spawning.mysite defaults # - Start your server: # $ sudo /etc/init.d/spawning.mysite start NAME="spawning.debian" # change debian to your own site DESC="Starts a Spawning daemon to run [domain here]" # This is where your app or settings.py lives SITE_DIR=/var/www/mysite/ # CONFIGURATION - edit this stuff # Configure your own spawning here SPAWNING_BIN=/usr/local/bin/spawning #Path to Spawning executable PROCESSES=2 # Number of processes to spawn # Django by default: delete this var to run a WSGI app FACTORY="spawning.django_factory.config_factory" PORT="8080" HOST="127.0.0.1" # listen on loopback by default CHUID="" ACCESS_LOG=/dev/null ERROR_LOG=/dev/null APP="settings" # Django by default, but put your own app here # END CONFIGURATION # Don't edit this PIDFILE=/var/run/$NAME.pid # make sure the access_log file exists if [ ! -e $ACCESS_LOG ]; then touch $ACCESS_LOG fi # make sure the error log file exists if [ ! -e $ERROR_LOG ]; then touch $ERROR_LOG fi start() { echo -n "Starting $NAME on $HOST:$PORT...: " DAEMON_ARGS="--host=$HOST --port=$PORT" DAEMON_ARGS="$DAEMON_ARGS --stderr=$ERROR_LOG --access-log-file=$ACCESS_LOG" [ -n "$PROCESSES" ] && DAEMON_ARGS="$DAEMON_ARGS --processes=$PROCESSES" [ -n "$FACTORY" ] && DAEMON_ARGS="$DAEMON_ARGS --factory=$FACTORY" [ -n "$CHUID" ] && DAEMON_ARGS="$DAEMON_ARGS --chuid=$CHUID" [ -n "$EXTRA_ARGS" ] && DAEMON_ARGS="$DAEMON_ARGS $EXTRA_ARGS" DAEMON_ARGS="$DAEMON_ARGS $APP" /sbin/start-stop-daemon --start --background --make-pidfile --pidfile=$PIDFILE --chdir $SITE_DIR --exec $SPAWNING_BIN -- $DAEMON_ARGS || return 2 echo $NAME return 0 } stop () { echo -n "Stopping $NAME: " /sbin/start-stop-daemon --stop --pidfile $PIDFILE rm -f $PIDFILE echo $NAME return } status() { if [ -f "$PIDFILE" ]; then echo -n "$NAME already running with PIDs: " && cat $PIDFILE && echo else echo "$NAME not running" fi return } case "$1" in start) start ;; stop) stop ;; status) status ;; restart) stop sleep 1 start ;; *) echo "Usage: $NAME (start|stop|status|restart)" exit 1 ;; esac exit $?