Apache Tomcat init script

Just the code, and only the code.

Here’s the script. For Red Hat Enterprise and downstream distributions running a .tar.gz binary package downloaded from Apache Tomcat site (not the shipping RHEL version of Tomcat). Tested with versions of Tomcat from version 5 to 7 (latest as of this writing).

#!/bin/bash
# Apache Tomcat init script
# /etc/rc.d/init.d/tomcat
#
# chkconfig: 345 99 28
# description: Starts/Stops Apache Tomcat
#
JAVA_HOME=/usr/java/default
CATALINA_HOME=/opt/apache/tomcat
CATALINA_BASE=$CATALINA_HOME
PATH=$JAVA_HOME/bin:$CATALINA_HOME/bin:$PATH
APPUSR=tomcat

case "$1" in
'start')
        echo "Apache Tomcat starting..."
        su - $APPUSR <<EOS
        $CATALINA_HOME/bin/startup.sh
EOS
        ;;
'stop')
        echo "Apache Tomcat stopping..."
        su - $APPUSR <<EOS
        $CATALINA_HOME/bin/shutdown.sh
EOS
        ;;
*)
        echo "Usage: $0 { start | stop }"
        exit 1
        ;;
esac