まとめページ

2011/04/17

chkconfig対応のHudson init script

/usr/local/hudson/hudson:

#!/bin/sh
/usr/lib/jvm/java-6-sun/bin/java $HUDSON_JVM_OPTS -jar /usr/local/hudson/hudson.war


/etc/init.d/hudson:

#!/bin/sh
# chkconfig: 345 98 20
# description: Hudson
# processname: java

PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
DAEMON=/usr/local/hudson/hudson
NAME=hudson
DESC="Hudson"
USER=repos
PIDFILE=/var/run/$NAME.pid
LOG=/var/log/$USER/hudson_stdout.log
HTTP_PROXY_HOST=www-proxy.sra.co.jp
HTTP_PROXY_PORT=80
export HUDSON_JVM_OPTS="-Xmx128m -server -Dhttp.proxyHost=$HTTP_PROXY_HOST -Dhttp.proxyPort=$HTTP_PROXY_PORT -Dhttps.proxyHost=$HTTP_PROXY_HOST -Dhttps.proxyPort=$HTTP_PROXY_PORT"

test -x $DAEMON || exit 0

if [ -f /etc/default/$NAME ]; then
. /etc/default/$NAME
fi

get_pid() {
PID=`ps ax|grep hudson.war|grep -v grep|awk '{print $1}'`
}

start_proc() {
cd /tmp
sudo -u $USER $DAEMON 1>$LOG 2>&1 &
if [ "$?" -eq 0 ]; then
sleep 1
get_pid
echo $PID > $PIDFILE
return 0
fi
return 1
}

stop_proc() {
kill -9 `cat $PIDFILE 2>/dev/null`
[ "$?" -ne 0 ] && return 1
rm -f $PIDFILE
return 0
}

status_proc() {
get_pid
[ "$PID" != "" ];
return $?
}

case "$1" in
start)
echo "Starting ${DESC}"
start_proc
[ "$?" -eq 0 ] || echo "failed"
;;
stop)
echo "Shutting down ${DESC}"
stop_proc
[ "$?" -eq 0 ] || echo "failed"
;;
restart|force-reload)
echo "Restarting ${DESC}"
stop_proc
if [ $? -ne 0 ]; then
failure ; echo ; exit 0
fi
sleep 1
start_proc
[ "$?" -eq 0 ] || echo "failed"
;;
status)
status_proc
[ $? -eq 0 ] && echo "$DESC is alive" || echo "$DESC is dead"
echo
;;
*)
echo "Usage: $0 {start|stop|restart|force-reload|status}" >&2
exit 1
;;
esac
exit 0

0 件のコメント:

コメントを投稿