Daemon monitors tomcat and proactively restarts itself

Source: Internet
Author: User

Yesterday's tomcat question. One day, 3, 4, can't stand the decision to write a script that monitors the Tomcat process and restarts itself proactively!

Check the information on the Internet. There are two main categories: one is to restart Tomcat on a timed basis, which is certainly not what I need. Another category is monitoring and restarting. There are also several version numbers. I synthesized the comparison (mainly this http://hi.baidu.com/tedzhangzhe/item/4afd87aa1cf2d1f215329b8a), removed some unnecessary content, and changed the code such as the following:

############################################ author# Date 2014/05/19# update 2014/05/19# Automatic detection and Restart tomcat############################################ echo ========================================DATECD/ Usr/local/share/tomcat7/bin/scriptrm-f main.jsp wget-t 10-t 3-q http://10.0.210.100:8080/pmonitor/main.jspif [!-e Ma IN.JSP]; Then        echo "Restart Tomcat."        Export java_home=/usr/local/java/jdk1.6.0_37        /usr/local/share/tomcat7/bin/shutdown.sh        sleep        Kill- 9 ' PS aux|grep "/usr/local/share/tomcat7" |grep-v Grep|awk ' {prin        T-$} '        sleep 5        /USR/LOCAL/SHARE/TOMCAT7 /bin/startup.shelse        echo "checked." Fi

1. Copy the code into the monitor.sh document and put it in the Usr/local/share/tomcat7/bin (the path is your own choice.) If you change the path, replace the relevant content in the code with the new path.

2, sudo chmod a+x monitor.sh plus permissions.

3, sudo crontab-e, add */2 * * * */usr/local/share/tomcat7/bin/monitor.sh at the end of the document. This script is executed every 2 minutes within the full-day range.

I have set the JAVA_HOME environment variable in the. bashrc file, but the execution is still an error. Tip Neither the java_home nor the JRE_HOME environment variable is defined. So have to add in the code of export java_home=/usr/local/java/jdk1.6.0_37 and defined again, have to know why please advise ha.

Test session: Manually close Tomcat after. 2 minutes later Ps-ef |grep Tomcat. and self-initiated, success.


To summarize, the method of this code is not to directly monitor tomcatport, but to test by wget transfer files. We all know that wget is able to go through the HTTP protocol and is able to pass Tomcat to test whether the service is valid. Very ingenious app!

Similarly, other services can be monitored.


Daemon monitors tomcat and proactively restarts itself

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.