Creating a Continuous Integration enviroment for Flex with Hudson ( 2 )

Categories: flex
Written By: sebi

One of our projects reached the level of complexity by both the term of codebase and developer-hours that we decided to go for a test ride with a CI ( Continuous Integration ) server.

So we have all the prefaces to run our general build server, it’s time to fine tune it.

Preparing Hudson

We saw that our build server runs well, so copy some scripts to ensure the start up and easy management of the it.

http://www.wakaleo.com/component/content/article/206
http://weblogs.java.net/blog/johnsmart/archive/2008/10/installing_huds.html
http://www.lostechies.com/blogs/jason_meridth/archive/2009/01/15/continuous-integration-for-a-ruby-project-or-net-java-etc.aspx

Create the start-up script:

hudson@sebesteny:~$ sudo nano /usr/local/bin/start-hudson.sh
 
#!/bin/bash
HUDSON_WAR=/home/hudson/hudson.war
HUDSON_LOG=/home/hudson/hudson.log
JAVA=/usr/bin/java
nohup nice $JAVA -jar $HUDSON_WAR > $HUDSON_LOG 2>&1 &
 
sudo chmod 755 /usr/local/bin/start-hudson.sh

The stop script

sudo nano /usr/local/bin/stop-hudson.sh
 
#!/bin/bash
kill `ps -ef | grep hudson.war | grep -v grep | awk '{ print $2 }'`	
 
hudson@sebesteny:~$ sudo chmod 755 /usr/local/bin/stop-hudson.sh

and the autostart

hudson@sebesteny:~$ sudo nano /etc/init.d/hudson
 
#! /bin/bash
### BEGIN INIT INFO
# Provides:             hudson
# Required-Start:       $remote_fs $syslog
# Required-Stop:        $remote_fs $syslog
# Default-Start:        2 3 4 5
# Default-Stop:         0 1 6
# Short-Description:    Start/Stop the Hudson Continuous Integration server.
# Description:          Hudson is a Continuous Integration server. \
#                       It monitors a source code repository and triggers builds \
#                       when it detects any changes. See https://hudson.dev.java.net/ \
#                       for more details.
### END INIT INFO
 
# processname: hudson
# pidfile: /var/run/hudson.pid
 
startup=/usr/local/bin/start-hudson.sh
shutdown=/usr/local/bin/stop-hudson.sh
HUDSON_USER=hudson
 
start(){
 echo -n $"Starting Hudson service: "
 su - $HUDSON_USER -c $startup
 RETVAL=$?
	 echo
	}
 
	stop(){
	 action $"Stopping Hudson service: " 
	 su - $HUDSON_USER -c $shutdown 
	 RETVAL=$?
	 echo
	}
 
	status(){
	 numproc=`ps -ef | grep hudson.war | grep -v "grep hudson.war" | wc -l`
	 if [ $numproc -gt 0 ]; then
	  echo "Hudson is running..."
	  else
	  echo "Hudson is stopped..."
	 fi
	}
 
	restart(){
	  stop
	  start
	}
 
 
	# See how we were called.
	case "$1" in
	start)
	 start
	 ;;
	stop)
	 stop
	 ;;
	status)
	 status
	 ;; 
	restart)
	 restart
	 ;;
	*)
	 echo $"Usage: $0 {start|stop|status|restart}"
	 exit 1
	esac
 
	exit 0

add to bootup and set the runlevels

hudson@sebesteny:~$ sudo update-rc.d hudson defaults
 Adding system startup for /etc/init.d/hudson ...
   /etc/rc0.d/K20hudson -> ../init.d/hudson
   /etc/rc1.d/K20hudson -> ../init.d/hudson
   /etc/rc6.d/K20hudson -> ../init.d/hudson
   /etc/rc2.d/S20hudson -> ../init.d/hudson
   /etc/rc3.d/S20hudson -> ../init.d/hudson
   /etc/rc4.d/S20hudson -> ../init.d/hudson
   /etc/rc5.d/S20hudson -> ../init.d/hudson

If you reboot, you should see it running automatically ( of course IP depends on your server )

http://192.168.1.59:8080/

Leave a Reply