#!/bin/bash # # Startup script for Hudson # Source function library. [ -z "$JAVA_HOME" -a -x /etc/profile.d/java.sh ] && . /etc/profile.d/java.sh HUDSON_HOME=/var/hudson WAR="/usr/local/bin/hudson/hudson.war" LOG="/var/log/hudson.log" LOCK="/var/run/hudson" export HUDSON_HOME RETVAL=0 pid_of_hudson() { ps auxwww | grep java | grep hudson | grep -v grep | awk '{print $2}' } start() { [ -e "$LOG" ] && cnt=`wc -l "$LOG" | awk '{ print $1 }'` || cnt=1 echo -n $"Starting hudson: " cd "$HUDSON_HOME" nohup java -jar "$WAR" >> "$LOG" 2>&1 & while { pid_of_hudson > /dev/null ; } && ! { tail -n $cnt "$LOG" | grep -q 'Winstone Servlet Engine .* running' ; } ; do sleep 1 done pid_of_hudson > /dev/null RETVAL=$? [ $RETVAL = 0 ] && echo -n "success" || echo -n "failed" echo [ $RETVAL = 0 ] && touch "$LOCK" } stop() { echo -n "Stopping hudson: " pid=`pid_of_hudson` [ -n "$pid" ] && kill $pid RETVAL=$? cnt=10 while [ $RETVAL = 0 -a $cnt -gt 0 ] && { pid_of_hudson > /dev/null ; } ; do sleep 1 ((cnt--)) done [ $RETVAL = 0 ] && rm -f "$LOCK" [ $RETVAL = 0 ] && echo -n "success" || echo -n "failed" echo } status() { pid=`pid_of_hudson` if [ -n "$pid" ]; then echo "hudson (pid $pid) is running..." return 0 fi if [ -f "$LOCK" ]; then echo $"${base} dead but subsys locked" return 2 fi echo "hudson is stopped" return 3 } # See how we were called. case "$1" in start) start ;; stop) stop ;; status) status ;; restart) stop start ;; *) echo $"Usage: $0 {start|stop|restart|status}" exit 1 esac exit $RETVAL