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.
3933c7e
if [ -x /etc/rc.d/init.d/functions ]; then
3933c7e
    . /etc/rc.d/init.d/functions
3933c7e
fi
3933c7e
3933c7e
[ -r /etc/java/java.conf ] && . /etc/java/java.conf
3933c7e
export JAVA_HOME
3933c7e
3933c7e
# Get Jetty5'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
3933c7e
RETVAL=0
3933c7e
3933c7e
start() {
3933c7e
    echo -n "Starting $JETTY_PROG: "
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
3933c7e
#        touch $JETTY_PID
3933c7e
#        chown $JETTY_USER:$JETTY_USER $JETTY_PID
3933c7e
3933c7e
#	[ -x ${JETTY_HOME}/ext ] &&
3933c7e
#	  	rebuild-jar-repository -s ${JETTY_HOME}/ext
3933c7e
3933c7e
        if [ -x /etc/rc.d/init.d/functions ]; then
3933c7e
                daemon --user $JETTY_USER $JETTY_SCRIPT start
3933c7e
        else
3933c7e
                su - $JETTY_USER -c "$JETTY_SCRIPT start"
3933c7e
        fi
3933c7e
3933c7e
        RETVAL=$?
3933c7e
        echo
5dd50a3
        [ $RETVAL = 0 ] && touch /var/lock/subsys/jetty
3933c7e
        return $RETVAL
3933c7e
}
3933c7e
3933c7e
3933c7e
stop() {
3933c7e
    echo -n "Stopping $JETTY_PROG: "
3933c7e
                                                                                                                                                             
5dd50a3
    if [ -f /var/lock/subsys/jetty ] ; then
3933c7e
      if [ -x /etc/rc.d/init.d/functions ]; then
3933c7e
          daemon --user $JETTY_USER $JETTY_SCRIPT stop
3933c7e
      else
3933c7e
          su - $JETTY_USER -c "$JETTY_SCRIPT stop"
3933c7e
      fi
3933c7e
      RETVAL=$?
3933c7e
3933c7e
      if [ $RETVAL = 0 ]; then
3933c7e
        count=0;
3933c7e
5dd50a3
        if [ -f /var/run/jetty/jetty.pid ]; then
3933c7e
3933c7e
            read kpid < $JETTY_PID
3933c7e
            let kwait=$SHUTDOWN_WAIT
3933c7e
3933c7e
            until [ `ps --pid $kpid 2> /dev/null | grep -c $kpid 2> /dev/null` -eq '0' ] || [ $count -gt $kwait ]
3933c7e
            do
3933c7e
                echo "waiting for processes to exit";
3933c7e
                sleep 1
3933c7e
                let count=$count+1;
3933c7e
            done
3933c7e
                                                                                                                                                             
3933c7e
            if [ $count -gt $kwait ]; then
3933c7e
                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
3933c7e
      fi
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
        ;;
3933c7e
  restart)
3933c7e
        stop
3933c7e
        sleep 2
3933c7e
        start
3933c7e
        ;;
3933c7e
  condrestart)
3933c7e
        if [ -f $JETTY_PID ] ; then
3933c7e
                stop
3933c7e
                start
3933c7e
        fi
3933c7e
        ;;
3933c7e
  *)
3933c7e
        echo "Usage: $JETTY_PROG {start|stop|restart|condrestart}"
3933c7e
        exit 1
3933c7e
esac
3933c7e
                                                                                                                                                             
3933c7e
exit $RETVAL
3933c7e
3933c7e
#
3933c7e
#
3933c7e
# end