Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

automatic restart of tomcat 1

Status
Not open for further replies.

proggy

Programmer
Apr 21, 2002
46
US
Hi there,
I was wondering how to restart a tomcat 4.0.5 v tomcat web server automatically after the system boot-up . I installed tomcat on linux system.

Thanks,
 
Ok usually the install processs places a startup script in /etc/init.d and if enabled then the init process will automatically start the daemon at what ever run level it has been set for.

If not you need to set something up. You should have a tomcat4 start-up file that you use to manually start it, yes?

Ok it may look similar to the following:
<START EXAMPLE OF START-UP SCRIPT ignore my numbers 1)-6) for now>
1)#!/bin/sh
2)#
3)# Added by Laurie to allow chkconfig -----
4)# chkconfig: 345 80 20
5)# description: Tomcat4 is the Apache Servlet Engine for worker 1
6)#
# Wrapper script for Tomcat 4.0, to be sure it will allways
# be run with correct user profile (tomcat4 by default)
#
# derived from stuff in tomcat4.init
#
# Gomez Henri <hgomez@slib.fr>
# Keith Irwin <keith_irwin@non.hp.com>
# Nicolas Mailhot <nicolas.mailhot@one2team.com>
#
# Source function library.
. /etc/rc.d/init.d/functions

# Get Tomcat config

TOMCAT_CFG=&quot;/etc/tomcat4/conf/tomcat4.conf&quot;

[ -r &quot;$TOMCAT_CFG&quot; ] && . &quot;${TOMCAT_CFG}&quot;

# Path to the tomcat launch script
TOMCAT_SCRIPT=/usr/bin/dtomcat4

# Tomcat name :)
TOMCAT_PROG=tomcat4

# if TOMCAT_USER is not set, use tomcat4
if [ -z &quot;$TOMCAT_USER&quot; ]; then
TOMCAT_USER=&quot;tomcat4&quot;
fi

# Since the daemon function will sandbox $tomcat
# no environment stuff should be defined here anymore.
# Please use the /etc/tomcat4/conf/tomcat4.conf file instead ; it will
# be read by the $tomcat script

RETVAL=0

su - $TOMCAT_USER -c &quot;$TOMCAT_SCRIPT $@&quot;
RETVAL=$?
exit $RETVAL
<END OF EXAMPLE>

Ok now what you can do is locate your start-up script and do one of two things, 1) copy it to /etc/init.d/tomcat or 2) make a symbolic link to it in /etc/init.d with the following: ln -s /var/tomcat/bin/tomcat(.sh) /etc/init.d/tomcat
... Where my guess is that /var/tomcat4/bin is where you startup script was installed ammend where necessary.

Right so lets say you now have the script in /etc/init.d, now you need to add a couple of lines to allow the use of the chkconfig command. in my example script see lines 4 & 5 (note the numbers and following bracket should not be in the script it is just there to indicate what we are looking for but the # marks should remain)? these need adding into your script so vi the file and add &quot;at least&quot; those two lines, save the file and exit vi.

A quick description of those lines:
4)# chkconfig: 345 80 20
On Linux there is a command chkconfig that sets up the run level to start and stop any process that has an enabled script in /etc/init.d, don't just trust me, look at man chkconfig anyway this line tell's the command that this script can be set to start/stop at run level 34&5 the start number is 80 and the stop number is 20. so if this was &quot;all&quot; enabled then there would the following files (Sym-links) /etc/rc3.d/S80tomcat /etc/rc3.d/K20tomcat, /etc/rc4.d/S80tomcat /etc/rc4.d/K20tomcat and so on ....... See what's happening? .......... Ok I hope your with me now but I 'll go a bit more ... lets say the above is in place.. you boot your server and your normal run level is 3, the server werr's away and &quot;init&quot; runs through the levels untill it reaches your level 3, it processes all the files in rc3.d that have a S(tart)nnPROCESS in numeric order so its processed (Started) sendmail daemon with S79sendmail start and now comes to yours S80tomcat start.

Now your with me, so on shutdown it works opposite it processes files with the K(ill) K20tomcat stop; K21Sendmail stop etc .....
Ok knuff of that.

5)# description: Tomcat4 is the Apache Servlet Engine for worker 1
Line 5 is a comment for chkconfig.

Put it all together:
1) copy (or link) /var/tomcat4/bin/tomcat(.sh) to /etc/init.d
2) vi /etc/init.d/tomcat(.sh) and add 2 lines for chkconfig
3) add the script into teh run levels required with:
chkconfig --add tomcat; chkconfig --level 345 tomcat on
4) check if you have done it right with chkconfig --list tomcat

And that should be it.

I hope that answers your question.
Good Luck
Laurie.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top