John,
        Here is a script that will let you use Tomcat as a service.
Here it is:

#!/bin/bash
#
# Startup script for Jakarta Tomcat
#
# chkconfig: 345 84 16
# description: Jakarta Tomcat Java Servlet/JSP Container



TOMCAT_HOME=/usr/local/tomcat/tomcat-4.1.18
TOMCAT_START=/usr/local/tomcat/tomcat-4.1.18/bin/startup.sh
TOMCAT_STOP=/usr/local/tomcat/tomcat-4.1.18/bin/shutdown.sh

#Necessary environment variables
export CATALINA_HOME=/usr/local/tomcat/tomcat-4.1.18
export JAVA_HOME=/usr/java/jdk1.3.1_07
export LD_KERNEL_ASSUME="2.2.5"

# Source function library.
. /etc/rc.d/init.d/functions

# Source networking configuration.
. /etc/sysconfig/network

# Check that networking is up.
[ ${NETWORKING} = "no" ] && exit 0

#Check for tomcat script
if [ ! -f $TOMCAT_HOME/bin/catalina.sh ]
then
    echo "Tomcat not available..."
    exit
fi

start() {
    echo -n "Starting Tomcat: "
    daemon $TOMCAT_START
    echo
    touch /var/lock/subsys/tomcatd
# We may need to sleep here so it will be up for apache
#    sleep 5
#Instead should check to see if apache is up by looking for http.pid
}

stop() {
    echo -n $"Shutting down Tomcat: "
    daemon $TOMCAT_STOP
    rm -f /var/lock/subsys/tomcatd.pid
    echo
}

status() {
    ps ax --width=1000 | grep "[o]rg.apache.catalina.startup.Bootstrap
start" | awk '{printf $1 " "}' | wc | awk '{print $2}' >
/tmp/tomcat_process_count.txt
   read line < /tmp/tomcat_process_count.txt
if [ $line -gt 0 ]; then
    echo -n "tomcatd ( pid "
    ps ax --width=1000 | grep "[o]rg.apache.catalina.startup.Bootstrap
start" | awk '{printf $1 " "}'
    echo -n ") is running..."
else
    echo -n "Tomcat is stopped"
fi
}

case "$1" in
    start)
        start
        ;;
     stop)
        stop
        ;;
     restart)
        stop
        sleep 3
        start
        ;;
     status)
        status
        ;;
     *)
        echo "Usage: tomcatd {start|stop|restart|status}"
     exit 1
esac



If you save this as "tomcatd" in the /etc/init.d/ directory, you can
then do:

chkconfig --add tomcatd

Now, you can use the "Service" tool from the GUI to start/stop your
service PLUS assign it to start up at boot.  Also, the way it starts now
is:

/sbin/service tomcat start

You will notice the "Usage" portion of the script.  This will tell you
what parameters you can add:

/sbin/service tomcatd <parameter>

Hope this helps, Jeremy

P.S. - I got one for Apache also if you need it.  Remember to change the
path to your Tomcat installaion and the catalina.sh.

-----Original Message-----
From: John B. Moore [mailto:[EMAIL PROTECTED] 
Sent: Monday, March 10, 2003 7:05 AM
To: [EMAIL PROTECTED]
Subject: Starting Tomcat on Linux as a Service??

Folks,

    One can start Apache by placing the command in the rc.local

    /usr/local/apache/bin/apachectl.sh start

    but it appears that you can not do that with tomcat because of the 
need for various environmental variables (JAVA_HOME ..etc..)

    Any one have a suggestion on how to get both tomcat and apache to 
start (tomcat first) when the server reboots..???

     Thanks...

     John...


---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to