tags:

views:

383

answers:

4

I have a script that needs to run after tomcat has finished starting up and is ready to start deploying applications. I'm using $TOMCAT_HOME/bin/startup.sh which returns immediately. How can I wait until tomcat has finished starting up?

A: 

Depends on what you mean by finishing. What do you want to wait for?

You could, for example, have a script that hits a URL repeatedly until it gets a desirable result that would only be available once the app is properly initialized.

You could also have a context listener that writes out an "I'm ready" file that you use to signal the readiness of your application. (If you do this, be sure the file doesn't exist before starting your app container).

Dustin
A: 

There isn't an easy method. As far as startup.sh and catalina.sh are concerned, tomcat is running when they finish. Although, internally, tomcat is still initializing and starting contexts.

It would help to know if you were trying to find out if your context finished loading or if you are just wanting a general, "Tomcat is runnnig although your contexts might not be completely loaded..."

If it is the latter you could create a web app that simply has a context listener that will execute a script using Runtime. If you were handy, you could make the webapp configuable via the web.xml file to accept a parameter that points to the script to execute.

Mike
+1  A: 

Hi timdisney. There are probably several ways to do this. The trick we use is:

#!/bin/bash

until [ "`curl --silent --show-error --connect-timeout 1 -I http://localhost:8080 | grep 'Coyote'`" != "" ];
do
  echo --- sleeping for 10 seconds
  sleep 10
done

echo Tomcat is ready!

Hope this helps!

Matt Solnit
A: 

Personally, I would just watch catalinas log for a specific string depending on how your setup and what exact phase your looking for.

Loki
You mean "watch" programatically of course.
OscarRyz