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?

2 Answers 2


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
  • This seems to be configurable to do what I want (and much more). Thanks.
    – Michael
    Jun 29, 2014 at 16:42

This might help someone!!

If one do not want to use any monitoring tool, then set up an email configurtion in Ubuntu server using mailutils package.



To monitor Tomcat status you can use below script and set up cron job which runs every minute/hour/day according to your needs.


PUBLIC_IP=`wget http://ipecho.net/plain -O - -q ; echo`
EMAIL_BODY="Hi Admin,\n\n$PUBLIC_IP Tomcat is down at $(date -d "+330 minutes" +"%Y-%m-%d %T") IST, Please take necessary action.\n\n\nDo not reply to this email as it is auto generated by Ubuntu system\n"

tomcat_pid() {
  echo `ps aux | grep org.apache.catalina.startup.Bootstrap | grep -v grep | awk '{ print $2 }'`

start() {
  if [ -n "$pid" ] 
    echo "Tomcat is already running (pid: $pid)"
    # Start tomcat
    echo "Starting tomcat"
    /bin/sh $TOMCAT_HOME/bin/startup.sh

  return 0


 if [ -n "$pid" ]
    echo "Tomcat is running with pid: $pid"
    echo "Tomcat is not running"
    # send an email alert then start
    echo -e $EMAIL_BODY | mail -s "$PUBLIC_IP Tomcat is down" user@email.com
    echo "Mail sent"
    #remove cache and release memory occupied by heavy processes
exit 0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.