RE: Starting Tomcat on Linux as a Service??

2003-03-11 Thread Jeremy Whitlock
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]



Re: Starting Tomcat on Linux as a Service??

2003-03-11 Thread John B. Moore
Jon,

   Ok, making progress.. here is some info that might help others at 
my level...G .. but I still have a loose end...sigh

What I did:

Tomcat was not starting so I attempted to run the same start 
command from the commandline..

   .. and got a pile of permission denied

  .. I then added the tomcat user to the admin.. no help.. then to 
the root group.. better but still joy.. I then realized that it was only 
the $CATALINA_HOME/logs directory that was having problems so I then 
changed the permissions on that directory.. (I had installed tomcat as 
root... my bad, I guess..) adding write permissions to others

That got me started or so it seemed..

 No error, but no joy..  What is strange is that if I try on the 
commandline

   /bin/su tomcat $CATALINA_HOME/bin/startup.sh

  .. it still will not start Tomcat either..  only

$CATALINA_HOME/bin/startup.sh

...will start tomcat..  It appears that trying to run Tomcat under 
the user tomcat will not work..???

   ...I then removed the /bin/su tomcat from the script and...no joy 
either..

   Obviously there is more to this that I understand...

   Any thoughts on this mystery...??

   John...



Jon Roberts wrote:

John B. Moore wrote:

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


Instead of rc.local, it would be more customary to use an 
initialization script in /etc/init.d. Look in this path to find 
examples for other services. As far as how the scripts should read, 
here are some examples posted by another list member which are pretty 
instructive:

http://tinyurl.com/5s4x

Good luck.

Jon Roberts
www.mentata.com


-
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]


Re: Starting Tomcat on Linux as a Service??

2003-03-10 Thread Jon Roberts
John B. Moore wrote:
   Any one have a suggestion on how to get both tomcat and apache to 
start (tomcat first) when the server reboots..???
Instead of rc.local, it would be more customary to use an initialization 
script in /etc/init.d. Look in this path to find examples for other 
services. As far as how the scripts should read, here are some examples 
posted by another list member which are pretty instructive:

http://tinyurl.com/5s4x

Good luck.

Jon Roberts
www.mentata.com


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


Re: Starting Tomcat on Linux as a Service??

2003-03-10 Thread John B. Moore
Perfect, Just what I was hoping I would find

  John...

Jon Roberts wrote:

John B. Moore wrote:

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


Instead of rc.local, it would be more customary to use an 
initialization script in /etc/init.d. Look in this path to find 
examples for other services. As far as how the scripts should read, 
here are some examples posted by another list member which are pretty 
instructive:

http://tinyurl.com/5s4x

Good luck.

Jon Roberts
www.mentata.com


-
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]