Wednesday, September 30, 2009

Configuring CruiseControl as an OSX Startup Daemon

General


The purpose of this post is to describe how to configure a startup daemon for cruisecontrol on OSX. While CruiseControl ships with a startup script (cruisecontrol.sh), one would like CruiseControl to automatically start after system startup to avoid the manual step of starting it.

This post assumes previous knowledge with OSX, bash, and CruiseControl and does not attempt to cover how to install or generally configure CruiseControl on OSX. There are several articles covering the latter, while the topic of configuring CruiseControl startup daemon is only partially covered.

Creating the Daemon


• Navigate to the startup daemons folder

$ cd /Library/LaunchDaemons

• Create a new plist file named org.sourceforge.cruisecontrol.plist, the plist file will look something along these lines:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
 <dict>
         <key>Label</key>
         <string>org.sourceforge.cruisecontrol</string>
         <key>WorkingDirectory</key>
         <string>/usr/local/cruisecontrol</string>
         <key>ProgramArguments</key>
         <array>
                 <string>/System/Library/Frameworks/JavaVM.framework/Home/bin/java</string>
                 <string>-Xms128m</string>
                 <string>-Xmx256m</string>
                 <string>-Djavax.management.builder.initial=mx4j.server.MX4JMBeanServerBuilder</string>
                 <string>-Dcc.library.dir=/usr/local/cruisecontrol/lib</string>
                 <string>-Djetty.logs=/usr/local/cruisecontrol/logs</string>
                 <string>-jar</string>
                 <string>/usr/local/cruisecontrol/lib/cruisecontrol-launcher.jar</string>
                 <string>-jmxport</string>
                 <string>8000</string>
                 <string>-webport</string>
                 <string>8080</string>
                 <string>-rmiport</string>
                 <string>1099</string>
         </array>
         <key>EnvironmentVariables</key>
         <dict>
         </dict>
         <key>RunAtLoad</key>
         <true/>
         <key>Uses</key>
         <array>
                 <string>Network</string>
                 <string>Resolver</string>
         </array>
 </dict>
</plist>

Whats in the plist file?

• Label => Name of daemon, set to org.sourceforge.cruisecontrol

• WorkingDirectory => Location of the CruiseControl installation

• ProgramArguments => Java calls to cruisecontrol-launcher jar including configuration for CruiseControl port numbers, libs and log location. Add additional parameters as you see fit

• RunAtLoad => Run at startup, set to true

• Uses => Dependency on other services, in our case networking and resolver

Testing the Daemon


• Loading:

$ launchctl load org.sourceforge.cruisecontrol.plist

Use the above command to load the daemon. The system will do the same upon reboot, so this is only required when you are testing the daemon.

• Unloading:

$ launchctl unload org.sourceforge.cruisecontrol.plist

Use the above command to unload the daemon if and when it fails and you need to reload it again.

• Testing to see that the daemon is actually loaded

$ launchctl list

If everything went well, you should see you daemon listed (org.sourceforge.cruisecontrol) with a valid pid.

You can also monitor the startup process on cruiscontrol.log, or if you access to he UI, through the system's console.

No comments:

Post a Comment