Tomcat (re)starting & monitoring with Monit

1) Install monit

apt-get install monit -y

2) Config Monit for tomcat6

Create a monit config file for the tomcat6 init.d service

nano /etc/monit/conf.d/tomcat6.monit.conf

Append the following

check process tomcat with pidfile /var/run/
    start program = "/etc/init.d/tomcat6 start"
    stop program = "/etc/init.d/tomcat6 stop"

check host tomcat6 with address localhost 
    stop program = "/etc/init.d/tomcat6 stop" 
    start program = "/etc/init.d/tomcat6 restart" 
    if failed port 8080 and protocol http           
        then start

3) Check monit config syntax

monit -t

4) Restart monit to effect changes

service monit restart

5) Check monit

monit status

6) View Monit log files

tail -n 50 /var/log/monit.log