Edgewall Software

Here is a simple script to start bitten-slave as a daemon on Redhat derivatives. The example file below should be saved as 'bitten-slave' in '/etc/init.d'. This has been tested on CentOS 5.2, however should run from any system with only minimal changes. You will need to change the DAEMON_ARGS variable to contain a URL which reflects your server.

#!/bin/sh
#
# bitten-slave   startup script for the Bitten build slave
# processname:       bitten-slave
# config:            /etc/bitten/slave
# pidfile:           /var/run/bitten-slave.pid
# chkconfig: 2345 99 01
# description:       Bitten build slave

# Source function library.
. /etc/rc.d/init.d/functions

PATH=/sbin:/usr/sbin:/bin:/usr/bin
DESC="Bitten Slave"
NAME=bitten-slave
DAEMON=/usr/bin/$NAME
DAEMON_ARGS="--interval=15 https://trac.example.org/trac/builds"
DAEMON_USER=bitten-slave
PIDFILE=/var/run/$NAME.pid

# Exit if the package is not installed
[ -x "$DAEMON" ] || exit 0

# Read configuration variable file if it is present
[ -r /etc/sysconfig/bitten-slave/$NAME ] && . /etc/sysconfig/bitten-slave/$NAME

start() {
        echo -n $"Starting $NAME: "
        daemon --user="$DAEMON_USER" --pidfile="$PIDFILE" "$DAEMON $DAEMON_ARGS &"
        RETVAL=$?
        pid=`ps -A | grep $NAME | cut -d" " -f2`
        pid=`echo $pid | cut -d" " -f2`
        if [ -n "$pid" ]; then
                echo $pid > "$PIDFILE"
        fi
        echo
        return $RETVAL
}
stop() {
        echo -n $"Stopping $NAME: "
        killproc -p "$PIDFILE" -d 10 "$DAEMON"
        RETVAL="$?"
        echo
        [ $RETVAL = 0 ] && rm -f "$PIDFILE"
        return "$RETVAL"
}

case "$1" in
  start)
        start
        ;;
  stop)
        stop
        ;;
  restart)
        stop
        start
        ;;
  *)
        echo "Usage: $NAME {start|stop|restart}" >&2
        exit 1
        ;;
esac

exit $RETVAL