Log in
updated 11:29 AM UTC, May 4, 2016

Monit to start your Tomcat if it crashes

  • Written by Madhu V Rao
  • Published in General

In the last article we came to know how to monitor website/server for failures, but it doesnt automatically starts the server program.

This task is better done using Monit program.

Monit is an open source tool that monitors and also has capability of managing the server programs.

Lets see how to install and configure monit to automagically starting your Tomcat server if it crashes.

Type this command to install:

sudo apt-get install monit

Check if monit daemon is up and running:

sudo monit status

make sure you dont get any error in this step. if you receive error , then make sure to uncomment the following lines in your /etc/monit/monitrc file.

set httpd port 2812
allow localhost       

Any changes to monitrc needs to be reloaded, use the following command:

sudo monit reload

Now try the 'sudo monit status' command , you should get similar to following output:

System 'ip-10-253-55-46.us-west-2.compute.internal'
  status                            Running
  monitoring status                 Monitored
  load average                      [2.05] [2.03] [2.05]
  cpu                               0.6%us 0.2%sy 99.0%wa
  memory usage                      109216 kB [17.8%]
  swap usage                        0 kB [0.0%]
  data collected                    Thu, 09 Jan 2014 06:32:24

 

Now add the tomcat to the monit list by adding following lines in the /etc/monit/monitrc file:

check process tomcat7 with pidfile /run/tomcat7.pid
start program = "/etc/init.d/tomcat7 start" with timeout 60 seconds
stop program = "/etc/init.d/tomcat7 stop"

 

now retype the command : 

sudo monit reload

now  start or stop all the services monitored by the monit by using:

sudo monit start all
OR
sudo monit stop all

That's it.

Now if the tomcat crashes , after 60 seconds it automagically gets restarted using the monit program.

 

 


Powered by Bullraider.com
Follow Us on Twitter
Find Us on Facebook
Follow Us on Google
Follow Us on Pinterest