source: project/wiki/spiffy-init-script @ 36676

Last change on this file since 36676 was 31677, checked in by sjamaan, 5 years ago

Add lsb-compatible Spiffy init.d script for Debian

File size: 3.8 KB
Line 
1Here's an example init.d script for [[/egg/spiffy|Spiffy the webserver]], for use on Debian derivatives (created by [[/users/mario-domenech-goulart|Mario Domenech Goulart]]).
2
3This script has also been prepared to play well with the "chkconfig" command on Red Hat derivatives (Fedora, CentOS, ...).
4
5See below for a lsb-compatible script.
6
7<enscript highlight="shell">
8#! /bin/sh
9# -*- shell-script -*-
10
11# Make this script chkconfig compliant, start with runlevel 2345, exit prio 95 (lower) start prio 20 (higher)
12# chkconfig: 2345 95 20
13# description: Control script for the Spiffy CHICKEN webserver
14# processname: spiffy
15
16
17# This is /etc/init.d/spiffy on Debian systems
18# It assumes you have a "spiffy.scm" script in /usr/local/libexec and a log directory in /var/log/spiffy
19
20# Select which "csi" program to use; defaults to the one in $PATH
21CSI=csi
22# Use a longer trace buffer and a larger nursery size (optional)
23CSI_ARGS="-:s1m -:a200"
24
25DATE_FORMAT="+%Y-%m-%d %H:%M:%S"
26
27CONFIG_FILE="/usr/local/libexec/spiffy.scm"
28LOG_DIR="/var/log/spiffy"
29
30spiffy_start () {
31    if [ ! -d "$LOG_DIR" ]; then
32      echo "Log directory \"$LOG_DIR\" does not exist."
33      exit 0
34    fi
35
36    if [ ! -r "$CONFIG_FILE" ]; then
37      echo "Cannot find or read the configuration file. Please create or check the permissions of the following file: \"$CONFIG_FILE\"."
38      exit 0
39    fi
40
41    echo "Starting spiffy..."
42    echo "start: " `date "$DATE_FORMAT"` >> /var/log/spiffy/start-stop.log
43    (cd /var/log/spiffy; ulimit -c unlimited ; $CSI $CSI_ARGS -s /usr/local/libexec/spiffy.scm &)  </dev/null &> /var/log/spiffy/init.log
44}
45
46spiffy_stop () {
47    echo "Stopping spiffy..."
48    echo "stop: " `date "$DATE_FORMAT"` >> /var/log/spiffy/start-stop.log
49    pids=`ps ax | grep "[/]usr/local/libexec/spiffy.scm" | awk '{print $1}'`
50    if [ -z "$pids" ] ; then
51       echo "spiffy is not running"
52    else
53        for pid in $pids; do
54            echo "killing " $pid
55            kill $pid
56        done
57    fi
58}
59
60case "$1" in
61    start)
62        spiffy_start
63        ;;
64    stop)
65        spiffy_stop
66        ;;
67    restart)
68        spiffy_stop
69        sleep 1
70        spiffy_start
71        ;;
72    *) exit 1
73esac
74</enscript>
75
76The following script is compatible with LSB init.d scripts, and has been tested on a Debian Wheezy system:
77
78<enscript highlight="shell">
79#! /bin/sh
80### BEGIN INIT INFO
81# Provides:          spiffy
82# Required-Start:    $network
83# Required-Stop:     $network
84# Default-Start:     2 3 4 5
85# Default-Stop:
86# Short-Description: Start Spiffy the webserver
87### END INIT INFO
88
89. /lib/lsb/init-functions
90
91# Must make this script executable with a shebang line, or compile it
92DAEMON=/usr/local/libexec/spiffy.scm
93PIDFILE=/var/run/spiffy.pid
94
95test -x $DAEMON || exit 5
96
97case $1 in
98        start)
99                log_daemon_msg "Starting web server" "spiffy"
100                start-stop-daemon --start --quiet --oknodo --pidfile $PIDFILE --startas $DAEMON --make-pidfile $PIDFILE --background
101                log_end_msg $?
102                ;;
103        stop)
104                log_daemon_msg "Stopping web server" "spiffy"
105                start-stop-daemon --stop --quiet --oknodo --pidfile $PIDFILE
106                log_end_msg $?
107                ;;
108        restart|force-reload)
109                $0 stop && sleep 2 && $0 start
110                ;;
111        try-restart)
112                if $0 status > /dev/null; then
113                        $0 restart
114                else
115                        exit 0
116                fi
117                ;;
118        reload) # not implemented
119                exit 3
120                ;;
121        status)
122                status_of_proc $DAEMON "Spiffy"
123                ;;
124        *)
125                echo "Usage: $0 {start|stop|restart|try-restart|force-reload|status}"
126                exit 2
127                ;;
128esac
129</enscript>
Note: See TracBrowser for help on using the repository browser.