Jenkins jnlp slave init script

#!/bin/sh                                                                                                                                           
#
# jenkins-slave:    Launch a Jenkins BuildSlave instance on this node
#
# chkconfig:    - 99 01
# description:  Enable this node to fulfill build jobs
#

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

[ -f /etc/sysconfig/jenkins-slave ] && . /etc/sysconfig/jenkins-slave

JENKINS_URL="http://example.com/"
JENKINS_WORKDIR="/var/lib/jenkins"
JENKINS_USER="jenkins"
JENKINS_NODENAME="YOUR OWN NODENAME (e.g. exampleslave)"

[ -n "$JENKINS_URL" ] || exit 0
[ -n "$JENKINS_WORKDIR" ] || exit 0
[ -n "$JENKINS_USER" ] || exit 0
[ -n "$JENKINS_NODENAME" ] || exit 0

prog=Jenkins-BuildSlave

download_jar()
{
  curl -s -o slave.jar $JENKINS_URL/jnlpJars/slave.jar || exit 0
}

start()
{
  cd $JENKINS_WORKDIR
  [ -f slave.jar ] || download_jar

  echo -n $"Starting $prog: "

  su - $JENKINS_USER sh -c "\
    java -jar slave.jar \
    -jnlpUrl $JENKINS_URL/computer/$JENKINS_NODENAME/slave-agent.jnlp \
    >slave.log 2>&1 &"

  if [ $? = 0 ]; then echo '[OK]'; else echo '[NG]'; fi
}

stop()
{
  echo -n $"Shutting down $prog: "

  PID=`ps -ef | grep '[j]ava -jar slave.jar' | awk '{print $2}'`
  [ -n "$PID" ] && kill $PID

  if [ $? = 0 ]; then echo '[OK]'; else echo '[NG]'; fi
}

# See how we were called.
case "$1" in
  start)
    start
    ;;
  stop)
    stop
    ;;
  restart|reload)
    stop
    start
    ;;
  status)
    status java
    ;;
  *)
    echo $"Usage: $0 {start|stop|restart|reload}"
    exit 1
esac

exit 0