开发者

check the tomcat running or not? [duplicate]

开发者 https://www.devze.com 2023-01-23 06:00 出处:网络
This question already has answers here: 开发者_StackOverflow中文版 Closed 12 years ago. Possible Duplicate:
This question already has answers here: 开发者_StackOverflow中文版 Closed 12 years ago.

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


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


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.


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.


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

0

精彩评论

暂无评论...
验证码 换一张
取 消