LinuxQuestions.org
Help answer threads with 0 replies.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices


Reply
  Search this Thread
Old 12-04-2005, 04:18 PM   #1
maxhugen
LQ Newbie
 
Registered: Mar 2003
Location: Sydney, Australia
Distribution: Red Hat 7.1
Posts: 15

Rep: Reputation: 0
How To Boot Tomcat After Apache


I need to start the Tomcat jsp engine during boot after Apache has started. I believe that Apache is started by the script /etc/rc.d/init.d/httpd.

At the moment I manually run a separate script to start Tomcat once the server has booted.

How can I check that Apache is running, and then run my Tomcat script (tomcat_all)?


MTIA
 
Old 12-04-2005, 05:38 PM   #2
stickman
Senior Member
 
Registered: Sep 2002
Location: Nashville, TN
Posts: 1,552

Rep: Reputation: 53
You could simply call your Tomcat script from your Apache start script or make a copy of the Apache script and customize it for Tomcat.
 
Old 12-04-2005, 06:31 PM   #3
maxhugen
LQ Newbie
 
Registered: Mar 2003
Location: Sydney, Australia
Distribution: Red Hat 7.1
Posts: 15

Original Poster
Rep: Reputation: 0
Thanks.

I'm not too sure how to change the Apache script to do that (not too conversant with Linux etc).

My Apache script follows.... would you be able to suggest the appropriate lines of code to run /tomcat_all once http is running please?

Many thanks!
Max


#!/bin/bash
#
# Startup script for the Apache Web Server
#
# chkconfig: - 85 15
# description: Apache is a World Wide Web server. It is used to serve \
# HTML files and CGI.
# processname: httpd
# pidfile: /var/run/httpd.pid
# config: /etc/httpd/conf/access.conf
# config: /etc/httpd/conf/httpd.conf
# config: /etc/httpd/conf/srm.conf

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

[ -r /etc/sysconfig/apache ] && . /etc/sysconfig/apache

# This will prevent initlog from swallowing up a pass-phrase prompt if
# mod_ssl needs a pass-phrase from the user.
INITLOG_ARGS=""

# Path to the apachectl script, server binary, and short-form for messages.
apachectl=/usr/local/apache2/bin/apachectl
httpd=/usr/local/apache2/bin/httpd
prog=httpd
RETVAL=0

# Find the installed modules and convert their names into arguments httpd
# can use.
moduleargs() {
moduledir=/usr/lib/apache
moduleargs=`
/usr/bin/find ${moduledir} -type f -perm -0100 -name "*.so" | env -i tr '[:lower:]' '[:upper:]' | awk '{\
gsub(/.*\//,"");\
gsub(/^MOD_/,"");\
gsub(/^LIB/,"");\
gsub(/\.SO$/,"");\
print "-DHAVE_" $0}'`
echo ${moduleargs}
}

# The semantics of these two functions differ from the way apachectl does
# things -- attempting to start while running is a failure, and shutdown
# when not running is also a failure. So we just do it the way init scripts
# are expected to behave here.
start() {
echo -n $"Starting $prog: "
daemon $httpd `moduleargs` $OPTIONS
RETVAL=$?
echo
[ $RETVAL = 0 ] && touch /var/lock/subsys/httpd
return $RETVAL
}
stop() {
echo -n $"Stopping $prog: "
killproc $httpd
RETVAL=$?
echo
[ $RETVAL = 0 ] && rm -f /var/lock/subsys/httpd /var/run/httpd.pid
}
reload() {
echo -n $"Reloading $prog: "
killproc $httpd -HUP
RETVAL=$?
echo
}

# See how we were called.
case "$1" in
start)
start
;;
stop)
stop
;;
status)
status $httpd
RETVAL=$?
;;
restart)
stop
start
;;
condrestart)
if [ -f /var/run/httpd.pid ] ; then
stop
start
fi
;;
reload)
reload
;;
graceful|help|configtest)
$apachectl $@
RETVAL=$?
;;
*)
echo $"Usage: $prog {start|stop|restart|condrestart|reload|status|fullstatus|graceful|help|configtest}"
exit 1
esac

exit $RETVAL
 
Old 12-04-2005, 07:12 PM   #4
btmiller
Senior Member
 
Registered: May 2004
Location: In the DC 'burbs
Distribution: Arch, Scientific Linux, Debian, Ubuntu
Posts: 4,290

Rep: Reputation: 378Reputation: 378Reputation: 378Reputation: 378
Any easy way to do it is just to add a call to your script to /etc/rc.local. It's often best to use a full-fledged start/stop script, tohugh, so the service can be stopped cleanly on boot (by default, it is just terminated. I suspect Tomcat cleans itself up nicely when sent the TERM signal, but some things don't. In any case, the /etc/rc.local should work for starters.

BTW, Red Hat 7.1 is ancient. If you're looking at running a network Web server, you ought to upgrade to something current to take advantage of software improvements, security patches, etc.
 
Old 12-04-2005, 07:50 PM   #5
maxhugen
LQ Newbie
 
Registered: Mar 2003
Location: Sydney, Australia
Distribution: Red Hat 7.1
Posts: 15

Original Poster
Rep: Reputation: 0
Thanks for the advice. Yes, I'll look at upgrading my version of RedHat.

Re starting Tomcat, and shutting down, I kind of know that these processes are controlled via scripts in the /rc.d/init.d, /rc.d/rc0.d (etc) directories - I note they are named things like "K15httpd" and so on.

Would you be able to suggest which of the rc?.d directories I should put the start and stop Tomecat scripts, and what prefix I should use.

My apologies if these are rather 'dumb' questions...


Thanx
 
Old 12-04-2005, 08:02 PM   #6
btmiller
Senior Member
 
Registered: May 2004
Location: In the DC 'burbs
Distribution: Arch, Scientific Linux, Debian, Ubuntu
Posts: 4,290

Rep: Reputation: 378Reputation: 378Reputation: 378Reputation: 378
Basically, the SXXservice (where XX is some number from 00-99) are symlinks to a "master" script in /etc/rc.d/init.d. When your Linux system boots, it is configured to go into a particular runlevel, generally 3 or 5, but it can vary by distro. To figure it out, look for a line like "id:N:initdefault:" in /etc/inittab. The N is a number, and that is the default runlevel. The scripts that control that runlevel are in the /etc/rc.d/rcN.d directory (again N is the runlevel number). When the runlevel is entered, All of the S scripts are called in numerical order with the argument of "start", which effectively calls /etc/rc.d/init.d/service start.

You can use chkconfig to easily manage these scripts. Read its man page "man chkconfig" for details. Note that this advice only applies to distros that use System V style init (most do, including Red Hat, but a few such as Slackware use BSD style init scripts).
 
Old 12-04-2005, 08:16 PM   #7
maxhugen
LQ Newbie
 
Registered: Mar 2003
Location: Sydney, Australia
Distribution: Red Hat 7.1
Posts: 15

Original Poster
Rep: Reputation: 0
Thanks!

Looks like the default runlevel is 3.

I note httpd is prefixed "S85" and "K15", so I'll try "S86" and "K14" for tomcat, so that Tomcat starts after Apache, and stops before it.

Will try this in 8 hrs when no-one is using the server.

Thanks very much for the clear explanation and help!

Cheers, Max
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
How to start Apache and Tomcat with Linux boot montejr Linux - Newbie 2 04-23-2004 02:03 PM
Has anybody done Apache 2 + Tomcat 5? ZaijiaN Linux - Software 1 03-30-2004 07:17 PM
Why use Apache with Tomcat rather than just Tomcat itself? davee Linux - Software 1 08-21-2003 09:47 PM
apache and tomcat KaktusKnight Linux - General 3 01-27-2003 04:41 AM
Apache and Tomcat Marcel Linux - General 2 07-11-2001 08:24 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - General

All times are GMT -5. The time now is 01:03 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration