Configuring CruiseControl for Linux - No Fluff Just Stuff

Configuring CruiseControl for Linux

Posted by: Paul Duvall on March 24, 2007

A while back I posted a movie on installing and configuring CruiseControl on Windows, so I figured I’d give a brief overview in Linux. I am using Ubuntu so some of the examples may be different for you — depending on the UNIX/Linux flavor you’re using. This assumes that Java is in your system’s path. To verify, type:

echo $JAVA_HOME -or-
echo $PATH

Step 1
Download CruiseControl to a temporary location.

Step 2
Extract it to the location you wish to install it. For example:

unzip cruisecontrol.zip /opt

Step 3
Create a user and group and ensure that CruiseControl files are owned by this group. For instance, as root, create a cimasters group and a cimaster user:

/usr/sbin/useradd -G cimasters cimaster

If /usr/sbin/ has been added to your path, you only need to enter useradd.

Now, change the owner of all CruiseControl files like this:


chown cimaster:cimasters /opt/cruisecontrol-bin-2.6.1 -R

Step 4
Create a file to run CruiseControl as a service. This is based on the CruiseControl service code from the CruiseControl wiki.

#!/bin/sh
CC_USER=cimaster
CC_INSTALL_DIR=/opt/cruisecontrol-bin-2.6.1
CC_WORK_DIR=$CC_INSTALL_DIR
CC_LOGFILE_DIR=$CC_INSTALL_DIR
export JAVA_HOME=/opt/jdk1.5.0_11
PATH_ADDITIONS=
CC_WEBPORT=8484
CC_JMXPORT=8888
CC_RMIPORT=
NAME=cruisecontrol
DESC="CruiseControl - continuous integration build loop"
PATH=/opt/jdk1.5.0_11/bin:/usr/local/bin:/sbin:/usr/sbin:/usr/bin:/bin
if [ -n "$PATH_ADDITIONS" ]; then
PATH=$PATH_ADDITIONS:$PATH
fi
export PATH
CC_DAEMON=$CC_INSTALL_DIR/cruisecontrol.sh
CC_CONFIG_FILE=$CC_INSTALL_DIR/config.xml
CC_LOG_FILE=$CC_LOGFILE_DIR/cruisecontrol.log
CC_COMMAND="cd $CC_WORK_DIR; $CC_DAEMON -configfile $CC_CONFIG_FILE -webport $CC_WEBPORT -jmxport $CC_JMXPORT"
if [ -f /etc/default/cruisecontrol ]; then
. /etc/default/cruisecontrol
fi
test -f $CC_DAEMON || (echo "The executable $CC_DAEMON does not exist!" && 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')
env >> cc.startup.env
su $CC_USER -c "/bin/sh -c \"$CC_COMMAND >> $CC_LOG_FILE 2>&1\"" & RETVAL=$?
echo "$NAME started with jmx on port ${CC_JMXPORT}"
;;
'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

Name this file cruisecontrol and place it in the /etc/init.d directory. Then, type:
./cruisecontrol start

Open your browser to http://localhost:8484/ (or whichever port you chose).
CruiseControl on Ubuntu Linux
That should do it. Let me know if you have any questions.

Paul Duvall

About Paul Duvall

Paul M. Duvall is the CEO of Stelligent, a consulting firm that helps clients create production-ready software every day. He has worked in virtually every role on software projects: developer, project manager, architect and tester. He's been a featured speaker at many leading software conferences. He is the principal author of Continuous Integration: Improving Software Quality and Reducing Risk (Addison-Wesley, 2007; Jolt 2008 Award Winner). He contributed to the UML 2 Toolkit (Wiley, 2003), authors a series for IBM developerWorks called Automation for the people and authored a chapter in the No Fluff Just Stuff Anthology: The 2007 Edition (Pragmatic Programmers, 2007). He is passionate about automating software development and release processes. He actively blogs on IntegrateButton.com

Why Attend the NFJS Tour?

  • » Cutting-Edge Technologies
  • » Agile Practices
  • » Peer Exchange

Current Topics:

  • Languages on the JVM: Scala, Groovy, Clojure
  • Enterprise Java
  • Core Java, Java 8
  • Agility
  • Testing: Geb, Spock, Easyb
  • REST
  • NoSQL: MongoDB, Cassandra
  • Hadoop
  • Spring 4
  • Cloud
  • Automation Tools: Gradle, Git, Jenkins, Sonar
  • HTML5, CSS3, AngularJS, jQuery, Usability
  • Mobile Apps - iPhone and Android
  • More...
Learn More »