#!/bin/sh
#
# jetty This shell script takes care of starting and stopping jetty
#
# chkconfig: - 80 20
# description: The Jetty Webserver and Servlet Container
# processname: jetty
# pidfile: /var/run/jetty/jetty.pid
# config: /etc/jetty/jetty.conf
#
#
# Portions from tomcat4.init by:
#
# Gomez Henri <hgomez@users.sourceforge.net>
# Keith Irwin <keith_irwin@non.hp.com>
# Nicolas Mailhot <nicolas.mailhot@one2team.com>
#
#
# Source function library.
. /etc/init.d/functions
[ -r /etc/java/java.conf ] && . /etc/java/java.conf
export JAVA_HOME
# Get Jetty's config
JETTY_CFG="/etc/jetty/jetty.conf"
[ -r "$JETTY_CFG" ] && . "${JETTY_CFG}"
# Path to the jetty launch script (direct don't use the wrapper)
JETTY_SCRIPT=/usr/bin/djetty
# if JETTY_USER is not set, use jetty
if [ -z "$JETTY_USER" ]; then
JETTY_USER="jetty"
fi
# if JETTY_HOME is not set, use /usr/share/jetty
if [ -z "$JETTY_HOME" ]; then
JETTY_HOME="/usr/share/jetty"
fi
if [ -z "$SHUTDOWN_WAIT" ]; then
SHUTDOWN_WAIT=10
fi
if [ -z "$JETTY_PID" ]; then
JETTY_PID=/var/run/jetty/jetty.pid
fi
prog=jetty
RETVAL=0
start() {
if [ -f /var/lock/subsys/jetty ] ; then
if [ -f $JETTY_PID ]; then
read kpid < $JETTY_PID
if checkpid $kpid 2>&1; then
echo "process already running"
return -1
else
echo "lock file found but no process running for pid $kpid, continuing"
fi
fi
fi
echo -n $"Starting $prog: "
# [ -x ${JETTY_HOME}/ext ] &&
# rebuild-jar-repository -s ${JETTY_HOME}/ext
if [ -x /etc/rc.d/init.d/functions ]; then
daemon --user $JETTY_USER JETTY_PID=$JETTY_PID $JETTY_SCRIPT
else
su - $JETTY_USER -c "JETTY_PID=$JETTY_PID $JETTY_SCRIPT"
fi
RETVAL=$?
[ $RETVAL = 0 ] && touch /var/lock/subsys/jetty && success || failure
echo
return $RETVAL
}
stop() {
if [ -f /var/lock/subsys/jetty ] ; then
echo -n $"Stopping $prog: "
count=0;
if [ -f $JETTY_PID ]; then
read kpid < $JETTY_PID
let kwait=$SHUTDOWN_WAIT
# Try issuing SIGTERM
kill -15 $kpid
until [ `ps --pid $kpid 2> /dev/null | grep -c $kpid 2> /dev/null` -eq '0' ] || [ $count -gt $kwait ]
do
# echo "waiting for processes to exit";
sleep 1
let count=$count+1;
done
if [ $count -gt $kwait ]; then
# echo "killing processes which didn't stop after $SHUTDOWN_WAIT seconds"
kill -9 $kpid
fi
fi
rm -f /var/lock/subsys/jetty $JETTY_PID
success
echo
fi
}
# See how we were called.
case "$1" in
start)
start
;;
stop)
stop
;;
status)
status -p $JETTY_PID jetty
;;
restart|reload)
stop
sleep 2
start
;;
condrestart)
if [ -f $JETTY_PID ] ; then
stop
start
fi
;;
*)
echo "Usage: $0 {start|stop|status|restart|reload|condrestart}"
exit 1
esac
exit $RETVAL
#
#
# end