~ salmonella-environment-setup (master) /awful/init-scripts/debian


  1#!/bin/sh
  2# Start/stop/restart/reload the awful web framework.
  3#
  4### BEGIN INIT INFO
  5# Provides:          awful
  6# Required-Start:    $remote_fs $syslog $time
  7# Required-Stop:     $remote_fs $syslog $time
  8# Should-Start:
  9# Should-Stop:
 10# Default-Start:     2 3 4 5
 11# Default-Stop:
 12# Short-Description: Awful web framework
 13# Description:       A CHICKEN web framework on top of the Spiffy web server
 14### END INIT INFO
 15
 16PIDFILE=/var/run/awful.pid
 17NAME=awful
 18AWFUL=/home/chicken/local/chicken/bin/$NAME
 19AWFUL_ARGS=''
 20
 21# In some systems the pidfile might be (incorrectly) set to /etc
 22# if this pidfile is present, use it instead.
 23[ -e /etc/$NAME.pid ] && PIDFILE=/etc/$NAME.pid
 24[ -r /etc/default/$NAME ] && . /etc/default/$NAME
 25
 26. /lib/lsb/init-functions
 27
 28[ -e "/etc/$NAME/$NAME.conf" ] && AWFUL_ARGS="/etc/$NAME/$NAME.conf $AWFUL_ARGS"
 29[ -e "/etc/$NAME/privileged.conf" ] && AWFUL_ARGS="--privileged-code=/etc/$NAME/privileged.conf $AWFUL_ARGS"
 30
 31# Read configuration variable file if it is present
 32[ -r /etc/default/$NAME ] && . /etc/default/$NAME
 33
 34# Load the VERBOSE setting and other rcS variables
 35. /lib/init/vars.sh
 36
 37
 38is_running() {
 39    if [ -f "$PIDFILE" ]; then
 40        if pidofproc -p "$PIDFILE" >/dev/null; then
 41            return 0
 42        else
 43            return 1
 44        fi
 45    else
 46        return 1
 47    fi
 48}
 49
 50do_start() {
 51    # Return
 52    #   0 if daemon has been started
 53    #   1 if daemon was already running
 54    #   2 if daemon could not be started
 55    echo "Starting $NAME"
 56    if is_running; then
 57        echo "$NAME is already running."
 58    else
 59        rm -f $PIDFILE
 60        $AWFUL $AWFUL_ARGS 2>&1 > /var/log/awful/init.log &
 61        local pid=$!
 62        local exit_code=$?
 63        if [ "$exit_code" = "0" ]; then
 64            echo $pid > $PIDFILE
 65            return 0
 66        else
 67            return 2
 68        fi
 69    fi
 70}
 71
 72
 73do_stop() {
 74    echo "Stopping $NAME"
 75    if [ ! -f "$PIDFILE" ]; then
 76        echo "Could not determine $NAME pid (no $PIDFILE)."
 77        return 1
 78    fi
 79    local pid=`cat $PIDFILE`
 80    local cmdline=`cat /proc/$pid/cmdline`
 81    local cmd=`echo $AWFUL$AWFUL_ARGS | sed "s/ //g"`
 82    local killed=
 83
 84    if [ "$cmd" = "$cmdline" ]; then
 85        kill $pid
 86        for i in `seq 1 5`; do
 87            if pidofproc -p "$PIDFILE" >/dev/null; then
 88                echo -n .
 89                sleep 1
 90                kill $pid
 91            else
 92                killed=1
 93                break
 94            fi
 95        done
 96
 97        if [ $killed = "1" ]; then
 98            rm -f $PIDFILE
 99            return 0
100        else
101            return 1
102        fi
103    else
104        echo "Error stopping $NAME."
105        return 1
106    fi
107}
108
109
110do_restart() {
111    echo "Restarting $NAME"
112    do_stop
113    do_start
114    return $?
115}
116
117
118do_reload() {
119    # Considering awful defines a /reload page
120    echo "Reloading $NAME"
121    wget -O /dev/null http://localhost/reload &> /dev/null
122}
123
124
125do_status() {
126    if is_running; then
127        echo "running"
128        exit 0
129    else
130        if [ -e "$PIDFILE" ]; then
131            echo "failed to start"
132            exit 1
133        else
134            echo "not running"
135            exit 3
136        fi
137    fi
138}
139
140case "$1" in
141    start)
142        do_start
143        ;;
144
145    stop)
146        do_stop
147        ;;
148
149    restart)
150        do_restart
151        ;;
152
153    reload|force-reload)
154        do_reload
155        ;;
156
157    status)
158        do_status
159        ;;
160    *)
161        echo "Usage: /etc/init.d/$NAME {start|stop|status|restart|reload|force-reload}"
162        exit 2
163        ;;
164esac
165exit 0
Trap