2

Possible Duplicate:
Is Tomcat running?

hi,

i installed tomcat server in virtual machine. i want to check the tomcat server daily, it is running or not. if it is running or not it will send mail to my mail id. how i achieve?

can i do this one by using batch files

Thanks Murali

Community
  • 1
  • 1
krishna
  • 97
  • 2
  • 4
  • 6

4 Answers4

5

You can cron the following script which checks the status of the tomcat pid present in the $CATALINA_PID file. If the pid is dead, an email is sent.

kill -0 `cat $CATALINA_PID` > /dev/null 2>&1
if [ $? -gt 0 ]
then
    echo "Check tomcat" | mailx -s "Tomcat not running" support@dom.com
fi
dogbane
  • 266,786
  • 75
  • 396
  • 414
5

There are multiple answers to this, depending on what you mean by "running". For instance, @dogbane's answer tells you if a Tomcat process exists (modulo edge cases), and @Prabhakaran's answer tells you if Tomcat is listening on port 8080 (modulo different edge cases). But neither of these will pick up cases where Tomcat has stopped responding to requests.

@Elite's answer tells you if the default (e.g. ROOT) servlet is running, but this is probably not enough.

I'd recommend the following approach:

  • Pick some webapp pages that you care about. Ideally these should include pages that depend on back-end services / databases.
  • Create request URLs to fetch the pages, perform the queries, or whatever/
  • Use curl or wget to send the request URLs.
  • Use some kind of pattern matching to make sure that you are getting good results and not error pages.
  • If you get timeouts, unexpected response codes or error pages, crank out a mail message1.

This kind of thing is easier to do if you are running on a UNIX / Linux platform than on Windows because the tools you need to implement it should be either installed already, or easy to install using the package manager.


1 - Actually, that's a recipe for spamming yourself. A better idea is to deploy an event monitoring system that understands system states, does duplicate suppression and so on.

Stephen C
  • 698,415
  • 94
  • 811
  • 1,216
1

If tomcat is running, the easiest way (platform independent) is to type this url to any web browser (assuming your http port is configured to "80"): http://localhost:8080/. You can change localhost to any host server of choice. This will open a Tomcat page with the following message:

If you're seeing this page via a web browser, it means you've setup Tomcat successfully. Congratulations!

Otherwise netstat and see if anything runs on port 8080.


PS I just read that you want to send email notification if not running, the best way is to create a job that periodically 1) listens to port 8080 or 2) find if a tomcat process is up and running. Failure to meet 1) or 2) sends an email to system administrator.

Buhake Sindi
  • 87,898
  • 29
  • 167
  • 228
0

if your tomcat is in linux environment then you can use netstat command to check for the tomcat listening port 8080 and send mail using shell script

Prabhakaran
  • 169
  • 2
  • 12