0

I'm trying to start Hudson on Ubuntu automatically on boot with an init.d script. The script works fine when invoked manually (ie with ./hudson start), and has update-rc.d-generated sym-links in rc2-rc5, but it doesn't start on rebooting. Does anyone know what might be causing it to not work? The script is as follows (the hudson.log logfile is created at boot, but doesn't contain any output):


#!/bin/sh
### 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 Hudson at boot
# Description:       Start the Hudson CI server at boot
### END INIT INFO

CTL=/home/jcss-dev/hudson.war
LOGFILE=/home/jcss-dev/hudson.log

case "$1" in
    start)
                pid=`/bin/ps -Af | /bin/grep "hudson.war" | /bin/grep -v /bin/grep | /usr/bin/awk '{print $2}'`
                if [ "$pid" = "" ]; then
      echo -n "Starting Hudson... "
                    su - the-user-account-name -c "/usr/bin/java -jar $CTL > $LOGFILE 2>&1 &"
  else
      echo -n "Hudson is already running"
  fi
        ;;
    stop)
  pid=`/bin/ps -Af | /bin/grep "hudson.war" | /bin/grep -v /bin/grep | /usr/bin/awk '{print $2}'`
  if [ "$pid" != "" ]; then
      echo -n "Stopping Hudson... "
      kill -9 $pid
  else
      echo "Hudson is not running"
  fi
        ;;
    status)
                pid=`/bin/ps -Af | /bin/grep "hudson.war" | /bin/grep -v /bin/grep | /usr/bin/awk '{print $2}'`
                if [ "$pid" != "" ]; then
      echo -n "Hudson is running"
  else
      echo -n "Hudson is not running"
  fi
        ;;
    *)
        echo "Usage $0 start|stop|status"
        exit 1
        ;;
esac

exit 0
Denis Bazhenov
  • 9,680
  • 8
  • 43
  • 65
Ryan
  • 919
  • 11
  • 19
  • Just as an aside, you should use pgrep instead of trying to parse ps output to get the hudson PID. –  Apr 30 '11 at 13:32

3 Answers3

1

if its run manually, meaning there is nothing wrong with the script... make sure you copy/move it in /etc/init.d folder and check your link files in rc[2345].d dirs.

maybe this question should be in serverfault.com

Community
  • 1
  • 1
Abu Aqil
  • 804
  • 1
  • 7
  • 12
0

Have you added it to rc??

sudo update-rc.d hudson.sh defaults

It works for me...

mikkel
  • 1
0

At the risk of asking too basic of a question, I'm assuming the the su command in the start section of your script has "jcss-dev" in place of "the-user-account-name"?

Andrew B
  • 839
  • 9
  • 14
  • Yes, that was just a placeholder for the post. – Ryan Feb 15 '10 at 23:11
  • Is /home a local or NFS mount? I usually drop this kind of install in /opt. The only other thought I had was to make sure it starts as late in the boot order as you can. – Andrew B Feb 16 '10 at 13:18