Article Figure 1 Figure 2 Figure 3 Figure 4
Listing 1 Listing 2 sep2006.tar

Listing 2 Script to run CruiseControl as a daemon


#!/bin/bash

# Date: 2006-04-27
# Script: ccdaemon
# Description: Running the CruiseControl build loop as a daemon.
# Based on http://confluence.public.thoughtworks.org/display/CC/ \
# RunningCruiseControlFromUnixInit

### BEGIN INIT INFO
# Provides: CruiseControl
# Default-Start: 3 4 5
# Default-Stop: 0 1 2 6
# Description: CruiseControl 2.4 continuous integration build loop
### END INIT INFO

PATH=/sbin:/usr/sbin:/usr/bin:/bin
export PATH

NAME=CruiseControl
DESC="CruiseControl 2.4 continuous integration build loop"

CC_USER=cruise
CC_WORK_DIR=/home/cruise/Builds   
CC_INSTALL_DIR=/usr/local/cruisecontrol-2.4.1

CC_DAEMON=$CC_INSTALL_DIR/main/bin/cruisecontrol.sh
CC_CONFIG_FILE=$CC_WORK_DIR/config.xml
CC_LOG_FILE=$CC_WORK_DIR/cruisecontrol.log
CC_PORT=8082
CC_RMIPORT=1234
CC_COMMAND="$CC_DAEMON -configfile $CC_CONFIG_FILE -jmxport $CC_PORT \
  -rmiport $CC_RMIPORT"

test -f $CC_DAEMON || exit 0

if [ `id -u` -ne 0 ]; then
        echo "Not starting/stopping $DESC, you are not root."
        exit 4
fi

PARPID=`ps -ea -o "pid ppid args" | grep -v grep | grep \
  "${CC_DAEMON}" | sed -e 's/^  *//' -e 's/ .*//'`

if [ "${PARPID}" != "" ]
then
  PID=`ps -ea -o "pid ppid args" | grep -v grep | grep java | grep \
    "${PARPID}" | sed -e 's/^  *//' -e 's/ .*//'`
fi

case "$1" in
 
  'start')
  # going into the work dir allows for use of relative PATHs in the 
  # config file
    cd $CC_WORK_DIR
    su $CC_USER -c "$CC_COMMAND >> $CC_LOG_FILE 2>&1" & RETVAL=$? 
    echo "$NAME started with jmx on port ${CC_PORT}"
    ;;

  'stop')
    if [ "${PID}" != "" ]
    then
     kill -9 ${PID} ${PARPID}
      $0 status
      RETVAL=$?
    else
      echo "$NAME is not running"
      RETVAL=1
    fi
    ;;

  'status')
    # echo PARPIDs $PARPID
    # echo PIDs $PID
    kill -0 $PID >/dev/null 2>&1
    if [ "$?" = "0" ]
    then
      echo $NAME \(pids $PARPID $PID\) is running
      RETVAL=0
    else
      echo "$NAME is stopped"
      RETVAL=1
    fi
    ;;

  'restart')
    $0 stop && $0 start
    RETVAL=$?
    ;;

  *)
    echo "Usage: $0 { start | stop | status | restart }"
    exit 1
    ;;
esac
#echo ending $0 $$....
exit 0;