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