tomcat-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Jan Labanowski <...@osc.edu>
Subject Re: Apache - Tomcat startup race for port 8009?
Date Tue, 27 Feb 2001 16:25:38 GMT
You may want to read my notes on starting apache/tomcat at
http://www.ccl.net/cca/software/UNIX/apache/index.shtml

Jan

On Tue, 27 Feb 2001, Chris Haynes wrote:

> As far as I can read there are the following requirements when using
> Apache and Tomcat with AJP13 linking them:
> 
> 1) To have Apache forward requests using AJP13 requires Tomcat to
> listen on Port 8009 and Apache to send to it.
> 2) Tomcat must have opened that port for listening before Apache
> (mod_jk) attempts to use it,
> 3) In the standard "tomcat.sh start" sequence the script forks the
> tomcat process and returns before it can be sure the port has been
> opened.
> 4) In the alternative "tomcat.sh run" the script seems to block - the
> method Tomcat.start() seems not to return until tomcat is shut down
> (although looking at the source code for Tomcat and ContextManager I
> can't see why this is).
> 
> I need to have an unattended start-up configuration.
> 
> My concern is this:
> 
> If I write a shellscript that first starts tomcat (using tomcat.sh
> start or startup.sh), then starts Apache (httpd),
> there is an unmanaged race to port 8009 availability - Apache could
> start trying to use it before tomcat has opened it.
> 
> I have no data on the behaviour of mod_jk if it can't open the port -
> so I have to assume it can't cope.
> 
> I can't have an unmanaged race (even if this has not yet actually been
> observed).
> 
> Visually the problem situation appears realistic: apache appears to
> start much faster than tomcat , so there is a very real possibility
> that I could have incoming requests being processed by apache and
> forwarded to mod_jk before tomcat has finished initializing itself.
> 
> Have I missed something?
> 
> If I'm right that there is a race, has anyone come up with a sensible
> work-around?
> 
> My list of ways of approaching this (if I have to) include:
> 
> A) Write a small program which keeps trying to open port 8009 as a
> client - cycling and waiting until it finds the port open and put this
> between the tomcat and apache starts - but what then happens when it
> closes the port on finding it open without having sent a valid AJP13
> message? How well does the handler cope with this? I have looked at
> the code of Ajp13ConnectorRequest to see of there is some kind of
> valid "NO-OP" I could send to the port before closing it, but can't
> see one - and I can't find the AJP13 spec on the web.
> 
> B) Ask Linux which ports it has open, see if 8009 is open, and keep
> looping / waiting until it is
> 
> C) Scan the tomcat log - looking for a *recent* message saying it has
> started that connector (but my observation of tomcat source code is
> that processes seem to announce 'starting . . ' before they actually
> do it, so there would still be a race).
> 
> D) Write a new dummy ConnectionHandler class which responds to start()
> by writing a flag file somewhere I can see it. Place this after the
> AJP13 handler in 'server.xml' (. . . but does Tomcat *contract* to
> start connection handlers in the order in which they appear in
> server.xml? . . . ). I then have a test-wait loop program  called from
> the shellscript which waits for this flag file to appear before
> letting Apache start.
> 
> Obviously all of the 'state change' approaches check that the
> pre-start state is correct before starting tomcat.
> 
> D seems the most elegant - if I have to do anything myself.
> B seems the most 'correct' and fool-proof.
> 
> All comments / suggestions gratefully received.
> 
> Chris Haynes
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: tomcat-user-unsubscribe@jakarta.apache.org
> For additional commands, email: tomcat-user-help@jakarta.apache.org
> 

Jan K. Labanowski            |    phone: 614-292-9279,  FAX: 614-292-7168
Ohio Supercomputer Center    |    Internet: jkl@osc.edu 
1224 Kinnear Rd,             |    http://www.ccl.net/chemistry.html
Columbus, OH 43212-1163      |    http://www.osc.edu/


Mime
View raw message