Dashboard > CruiseControl > RunningCruiseControlFromUnixInit > UnixStartupScriptVersion1.x
UnixStartupScriptVersion1.x Log In View a printable version of the current page.

Added by kevin quigley , last edited by kevin quigley on Jul 20, 2006  (view change)
Labels: 
(None)

Use a script similar to the following:

#!/bin/sh

#
# Edit these variables to suit your Cruise Control installation
# chkconfig: - 345 99 05
# description: Script used to start and stop the CruiseControl auto-build system
#

CCDIR=/usr/local/bin/cruisecontrol-2.2.1
CCSTARTSCRIPT=${CCDIR}/main/bin/cruisecontrol.sh
CCCONFIGDIR=/var/local/cruisecontrol
CCCONFIGFILE=${CCCONFIGDIR}/config.xml
CCLOGFILE=/${CCDIR}/console.log
CCPORT=8082
CCCOMMAND="cd ${CCCONFIGDIR}; ${CCSTARTSCRIPT} -configfile ${CCCONFIGFILE} -port ${CCPORT}"

#
# DO NOT CHANGE ANTHING BELOW THIS LINE
#

umask 002

export CCDIR

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

case $1 in

  start)
    ${CCCOMMAND} > ${CCLOGFILE} 2>&1 & RETVAL=$?
    echo "cruisecontrol started with jmx on port ${CCPORT}"
    ;;

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

  status)
    kill -0 ${PID} >/dev/null 2>&1
    if [ "$?" = "0" ]
    then
      echo "cruisecontrol (pid ${PARENTPID} ${PID}) is running"
      RETVAL=0
    else
      echo "cruisecontrol is stopped"
      RETVAL=1
    fi
    ;;

  restart)
    $0 stop && $0 start
    RETVAL=$?
    ;;
  *)
    echo "Usage: $0 { start | stop | status | restart }"
    exit 1
    ;;

esac
exit ${RETVAL}

changelog

Removed quotes around case arguments and also around the case condition as they are not necessary at all.

The title of this page suggests that this page discusses a solution how to run CruiseControl (CC) as daemon, i.e. detached from terminal processes. None of the solutions described here are working. The start command shown above simply starts CC as background process, which is just one step in getting a daemon. Here's something that works for sure:

cd "$CCDIR" && su $CCUSER  -c "$CCEXEC > $CCDIR/ccd.log 2>&1 &"
  case $? in
    0)
      # check status 
      $0 status 
      exit $?
      ;;
    *)
      # error
      exit 1
      ;;
  esac

Here CCDIR is supposed to contain the directory hosting config.xml, typically something like /home/$CCUSER; CCUSER is the user CC will run as and CCEXEC shall contain the complete command to startup CC as standalone process. On my machine this is something like /opt/cruisecontrol/221/bin/cruisecontrol.sh -p 8000.

Note also that it's wise to change cruisecontrol.sh a bit to "exec" the final java command call. Otherwise daemon command above ends up in two processes, detached process 'cruisecontrol.sh' along with the Java command as kid.

geronimo <o r a dot e t dot l a b o r a at w e b dot d e>


Changed PPID to PARENTPID, as some versions of Bash make PPID read-only.
Added CCCONFIGDIR and made the CCCOMMAND cd to the CCCONFIGDIR before executing, making
this consistent with the default CC 2.2.1 config which is relative to the config directory.

Jayson Raymond <jraymond@accelerantmobile.com>


Made some additions to the script to make it more robust... stop now works as well as restart and status. Both the script and java process are killed.

John Schult <schultj@corp.earthlink.net>


The script may need environment variables set appropriately depending on the user that runs it (JAVA_HOME, ANT_HOME). init-experts: please add to this script to make it more robust.
-JonathanJulian

Note that this script may also be used standalone to start/stop the java process by any user.


I've made some changes to the original script:

  • specify a user to run the script
  • use su to call the cruisecontrol.sh script and pass the environment to the underlying script
  • some shell syntax changed (removal of "" or {}) in order to work with the fact that more than one process id will be returned.
    There may also be some changes due to the fact that the shells are different
  • do not use PPID as it is reserved in my shell (similar to a change already applied above)

The modified file is used on my moca public server and is attached on this page.

Jerome Lacoste

Simple explanation of Linux-init

Put this script into /etc/init.d (or wherever your system holds init-style scripts). Add symlinks in each of your /etc/rc.* directories to it (On RedHat, use chkconfig). Your mileage may vary, depending on your OS and level of UNIX admin expertise.

start/stop daemon orders

You should be able to start the build loop before or after the reporting, without any particular issue.

MOVE ME SOMEWHERE ELSE

tips

checkouts

I do not check out projects directly within the checkout directory but one level below:
i.e.
mkdir checkout/project-name/
cd checkout/project-name/
cvs co module

That way I can check out the same project under different project-name, if I have several versions/configurations/branches...

don't rely on external environment for your install

I prefer to specify the exact version of the software used in the config.xml instead of depending on the environment.
On a Linux box, as things are most of the time automatically updated, you'd better specify the version you want to use if you don't want breakages.

That would also make it easier to run the process in a chroot jail for the security freaks.
That way you can also probably automatically install most of the cruisecontrol setup.

Powered by a free Atlassian Confluence Open Source Project / Non-profit License granted to ThoughtWorks, Inc.. Evaluate Confluence today.
Powered by Atlassian Confluence 2.7.1, the Enterprise Wiki. Bug/feature request - Atlassian news - Contact administrators