Jason Meridth

Learn, Converse, Share

Hudson Service Files

06 Jun 2009 - San Antonio

This post is strictly for my reference. These scripts are dependent on an existing user named hudson with a home directory of /home/hudson and the hudson.war file being located at /usr/share/hudson/hudson.war.

/etc/init.d/hudson

#! /bin/bash
#
# hudson    Start/Stop the Hudson Continuous Integration server.
#
# chkconfig: 345 91 10
# 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.
# processname: hudson
# pidfile: /var/run/hudson.pid


# Source function library.
#. /etc/rc.d/init.d/functions

# Get config.
#. /etc/sysconfig/network

# Check that networking is up.
#[ "${NETWORKING}" = "no" ] && exit 0

startup=/usr/local/bin/start-hudson.sh
shutdown=/usr/local/bin/stop-hudson.sh
export JAVA_HOME=/usr/java/jdk1.6.0
HUDSON_USER=hudson

start(){
 echo -n $"Starting Hudson service: "
 su - $HUDSON_USER -c $startup
 RETVAL=$?
 echo
}

stop(){
 echo -n  $"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

/usr/local/bin/start-hudson.sh

#!/bin/bash
HUDSON_WAR=/usr/share/hudson/hudson.war
HUDSON_LOG=/home/hudson/hudson.log
java -jar $HUDSON_WAR > $HUDSON_LOG Z>&1 &

/usr/local/bin/stop-hudson.sh

#!/bin/bash
kill -9 `ps -ef | grep hudson.war | grep -v grep | awk '{print $2}'`

Comments