Tomcat – How to monitor tomcat application and restart if not running

tomcat

I have a web application running on Tomcat and would like to have an automated way of monitoring the application to ensure it is running, and if not start/restart tomcat (and also send an email alert). I'd like to do more than just check that Tomcat is running and ensure that a default page from the application can be loaded.

Is there any tool that would be best to do this, aside from writing a shell script and running it as a cron job?

Best Answer

Please look into the Monit utility.

This is a daemon and process-watching tool and can provide the alerts and defined actions that you may need.

A quick example:

check process tomcat with pidfile "/var/run/tomcat/tomcat.pid"
  start program = "/usr/local/tomcat/bin/startup.sh" as uid tomcat gid tomcat
  stop program = "/usr/local/tomcat/bin/shutdown.sh" as uid tomcat gid tomcat
  if failed port 8080 then alert
  if failed port 8080 for 5 cycles then restart
Related Topic