#!/bin/sh
##############################################################################
#
#   Copyright 2004 The Apache Software Foundation.
#
#   Licensed under the Apache License, Version 2.0 (the "License");
#   you may not use this file except in compliance with the License.
#   You may obtain a copy of the License at
#
#       http://www.apache.org/licenses/LICENSE-2.0
#
#   Unless required by applicable law or agreed to in writing, software
#   distributed under the License is distributed on an "AS IS" BASIS,
#   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
#   See the License for the specific language governing permissions and
#   limitations under the License.
##############################################################################
#
# Small shell script to show how to start/stop Tomcat using jsvc
# If you want to have Tomcat running on port 80 please modify the server.xml
# file:
#
#    <!-- Define a non-SSL HTTP/1.1 Connector on port 80 -->
#    <Connector className="org.apache.catalina.connector.http.HttpConnector"
#               port="80" minProcessors="5" maxProcessors="75"
#               enableLookups="true" redirectPort="8443"
#               acceptCount="10" debug="0" connectionTimeout="60000"/>
#
# That is for Tomcat-5.0.x (Apache Tomcat/5.0)
#
### BEGIN INIT INFO
# Provides:       tomcat
# Required-Start: $network $remote_fs $syslog $postgresql
# X-UnitedLinux-Should-Start: 
# Required-Stop:
# Default-Start:  3 5
# Default-Stop:   0 1 2 6
# Description:    Apache Tomcat Server 
### END INIT INFO

. /etc/rc.status
rc_reset

. /etc/profile.d/alljava.sh
. /etc/profile.d/tomcat.sh

DAEMON=$CATALINA_HOME/bin/jsvc
USER=tomcat

umask 000

# for multi instances adapt those lines.
TMP_DIR=/var/tmp
PID_FILE=/var/run/jsvc.pid

CLASSPATH=\
$JAVA_HOME/lib/tools.jar:\
$CATALINA_HOME/bin/commons-daemon.jar:\
$CATALINA_HOME/bin/bootstrap.jar

case "$1" in
  start)
    #
    # Start Tomcat
    #
    echo -n "Starting Apache Tomcat Server..." 
    $DAEMON \
    -user $USER \
    -home $JAVA_HOME \
    -Dcatalina.home=$CATALINA_HOME \
    -Dcatalina.base=$CATALINA_BASE \
    -Djava.io.tmpdir=$TMP_DIR \
    -wait 10 \
    -pidfile $PID_FILE \
    -outfile $CATALINA_HOME/logs/catalina.out \
    -errfile '&1' \
    $CATALINA_OPTS \
    -cp $CLASSPATH \
    org.apache.catalina.startup.Bootstrap
    #
    # To get a verbose JVM
    #-verbose \
    # To get a debug of jsvc.
    #-debug \
    rc_status -v 
    exit $?
    ;;

  stop)
    #
    # Stop Tomcat
    #
    echo -n "Stopping Apache Tomcat Server..."
    $DAEMON \
    -stop \
    -pidfile $PID_FILE \
    org.apache.catalina.startup.Bootstrap
    rc_status -v
    exit $?
    ;;

  restart)
    $0 stop
    $0 start
    rc_status
    exit $?
    ;;

  status)
    echo -n "Checking for Apache Tomcat Server..."
    checkproc -p $PID_FILE $DAEMON
    rc_status -v 
    ;;

  kill)
    echo -n "Killing Apache Tomcat Server..."
    kill -9 `cat $PID_FILE`
    rm $PID_FILE
    rc_status -v
    ;;

  *)
    echo "Usage: $0 start|stop|restart|status|kill"
    exit 1;;
esac

