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

Last change on this file since 29914 was 29914, checked in by Timusan, 8 years ago

Added Red Hat derivatives "chkconfig" support to the Spiffy init.d script.

File size: 2.1 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
5<enscript highlight="shell">
6#! /bin/sh
7# -*- shell-script -*-
8
9# Make this script chkconfig compliant, start with runlevel 2345, exit prio 95 (lower) start prio 20 (higher)
10# chkconfig: 2345 95 20
11# description: Control script for the Spiffy CHICKEN webserver
12# processname: spiffy
13
14
15# This is /etc/init.d/spiffy on Debian systems
16# It assumes you have a "spiffy.scm" script in /usr/local/libexec and a log directory in /var/log/spiffy
17
18# Select which "csi" program to use; defaults to the one in $PATH
19CSI=csi
20# Use a longer trace buffer and a larger nursery size (optional)
21CSI_ARGS="-:s1m -:a200"
22
23DATE_FORMAT="+%Y-%m-%d %H:%M:%S"
24
25CONFIG_FILE="/usr/local/libexec/spiffy.scm"
26LOG_DIR="/var/log/spiffy"
27
28spiffy_start () {
29    if [ ! -d "$LOG_DIR" ]; then
30      echo "Log directory \"$LOG_DIR\" does not exist."
31      exit 0
32    fi
33
34    if [ ! -r "$CONFIG_FILE" ]; then
35      echo "Cannot find or read the configuration file. Please create or check the permissions of the following file: \"$CONFIG_FILE\"."
36      exit 0
37    fi
38
39    echo "Starting spiffy..."
40    echo "start: " `date "$DATE_FORMAT"` >> /var/log/spiffy/start-stop.log
41    (cd /var/log/spiffy; ulimit -c unlimited ; $CSI $CSI_ARGS -s /usr/local/libexec/spiffy.scm &)  </dev/null &> /var/log/spiffy/init.log
42}
43
44spiffy_stop () {
45    echo "Stopping spiffy..."
46    echo "stop: " `date "$DATE_FORMAT"` >> /var/log/spiffy/start-stop.log
47    pids=`ps ax | grep "[/]usr/local/libexec/spiffy.scm" | awk '{print $1}'`
48    if [ -z "$pids" ] ; then
49       echo "spiffy is not running"
50    else
51        for pid in $pids; do
52            echo "killing " $pid
53            kill $pid
54        done
55    fi
56}
57
58case "$1" in
59    start)
60        spiffy_start
61        ;;
62    stop)
63        spiffy_stop
64        ;;
65    restart)
66        spiffy_stop
67        sleep 1
68        spiffy_start
69        ;;
70    *) exit 1
71esac
72</enscript>
Note: See TracBrowser for help on using the repository browser.