You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomcat.apache.org by Martin Stafford <ma...@spike.com.au> on 2001/11/06 01:30:28 UTC

Tomcat 4 management scripts, multiple instances and configuration

Here's some scripts I've written to manage multiple tomcat instances on our
Linux development server. It does the following things:
o Allows management of multiple instances
o Sends tomcat output to syslog so that it can be broadcast to development
workstations (they listen with netcat - nc.exe -l -u -p 514)
o Waits for tomcat to shutdown before restarting it

CATALINA_HOME should point to the location that you extracted tomcat to. I
use /usr/tomcat

CATALINA_BASE should point to a location containing unique copies of:
conf
work
logs
webapps
Your webapps could live somewhere else but I leave them there to keep all
the files for one instance together.
All of the ports listed in each $CATALINA_BASE/conf/server.xml must be
unique such as your warp listener, server port etc.

------------------------------------
Diff on catalina.sh
Adds syslog redirection, process id recording and classpath modifications
------------------------------------
98,101d97
< if [ -n "$CLASSPATH" ]; then
<   CP="$CP:$CLASSPATH"
< fi
< 
206,207c202
<         | logger -p user.debug -t "$CATALINA_BASE" &
< #     >> $CATALINA_BASE/logs/catalina.out 2>&1 &
---
>      >> $CATALINA_BASE/logs/catalina.out 2>&1 &
213,214c208
<         | logger -p user.debug -t "$CATALINA_BASE" &
< #     >> $CATALINA_BASE/logs/catalina.out 2>&1 &
---
>      >> $CATALINA_BASE/logs/catalina.out 2>&1 &
216d209
<   echo $! > $CATALINA_BASE/conf/tomcat.pid

------------------------------------
/etc/init.d/tomcat
Stops, Starts and Restarts tomcat
------------------------------------
# Process all Catalina instances
#
# chkconfig: 2345 80 20
# description: Tomcat Java Servlet/JSP containers
# usage: tomcat stop|start|restart [instance_file_name]

CONFIG_DIR="/etc/tomcat.d"

cd /

for i in $(ls $CONFIG_DIR); do
  if [ -z "$2" ] || [ $i = $2 ]; then
    CLASSPATH=""
    . $CONFIG_DIR/$i
    export JAVA_HOME CATALINA_HOME CATALINA_BASE CLASSPATH
    case "$1" in
      start)
        echo "Starting $CATALINA_NAME tomcat instance..."
        $CATALINA_HOME/bin/catalina.sh start
        ;;
      stop)
        echo "Stopping $CATALINA_NAME tomcat instance..."
        $CATALINA_HOME/bin/catalina.sh stop
        if [ -a $CATALINA_BASE/conf/tomcat.pid ]; then
          TOMCAT_PROCESS=$(cat $CATALINA_BASE/conf/tomcat.pid)
          if [ -d /proc/$TOMCAT_PROCESS ]; then
            echo -n "Waiting for process $TOMCAT_PROCESS ["
            while [ -d /proc/$TOMCAT_PROCESS ]; do
              echo -n "."
              sleep 1
            done
            echo "] Stopped"
          fi
          rm -f $CATALINA_BASE/conf/tomcat.pid
        fi
        ;;
      restart)
        /etc/init.d/tomcat stop $i
        /etc/init.d/tomcat start $i
        ;;
    esac
    echo
  fi
done
------------------------------------
Example /etc/tomcat.d/XXXXXXX
one for each instance of tomcat
------------------------------------
CATALINA_NAME="Development Instance"
JAVA_HOME="/usr/java/jdk1.3.1"
CATALINA_HOME="/usr/tomcat"
CATALINA_BASE="/sites/development/"

------------------------------------
Example $CATALINA_BASE/conf/server.xml - one for each instance
------------------------------------
<Server port="8002" shutdown="SHUTDOWN" debug="0">
        <Service name="dev.instance.server">
                <Connector
className="org.apache.catalina.connector.http.HttpConnector" port="8102"
minProcessors="5" maxProcessors="75" acceptCount="10" debug="0"
connectionTimeout="60000"/>
                <Connector className="org.apache.ajp.tomcat4.Ajp13Connector"
port="8152" address="127.0.0.1" acceptCount="10" debug="0"/>
                <Engine
className="org.apache.catalina.connector.warp.WarpEngine"
name="dev.instance.engine" debug="0"
defaultHost="dishlex-stage.spike.com.au">
                        <DefaultContext reloadable="true">
                                <Parameter name="serverType" value="dev"/>
                        </DefaultContext>
                        <Logger
className="org.apache.catalina.logger.FileLogger" prefix="catalina."
suffix=".log" timestamp="true"/>
                        <Realm
className="org.apache.catalina.realm.MemoryRealm"/>
                        <Host name="dev.company.com.au"
appBase="webapps/dev.company.com.au/root">
                                <Logger
className="org.apache.catalina.logger.FileLogger" directory="logs"
prefix="dev-company.tomcat." suffix=".log" timestamp="true"/>
                                <Context docBase="" path=""/>
                                <Context
docBase="/usr/tomcat/webapps/manager" path="/manager"/>
                        </Host>
                </Engine>
        </Service>
</Server>


Martin Stafford


<FONT SIZE=1 FACE="ARIAL" > 
<p>_____________________________________________________________________________

This e-mail (and any attachment) is intended only for the addressee and
may contain confidential information.  If you are not the intended recipient
you must not use, copy, print or distribute this e-mail. If you receive this
e-mail in error, please contact the sender and destroy the original.</p>
<p>This footnote also confirms that this email message has been swept by
MIMEsweeper for the presence of computer viruses.
_____________________________________________________________________________</p>
</FONT>