Tomcat automatic detection and restart scripts in Linux
Source: Internet
Author: User
We recommend that you store this script on the Linux server where tomcat is located, and create the/root/script directory. However, emails cannot be notified due to serious network, hardware, or system faults. Some functions of the script can be removed. it can be placed on other servers only for monitoring or restarting Tomcat. #/Bin/bash ############ the script is recommended to be placed on the Linux server where tomcat is located, and the/root/script directory is created and put in the directory.
However, emails cannot be notified due to serious network, hardware, or system faults. Some functions of the script can be removed. it can be placed on other servers only for monitoring or restarting Tomcat.
#/Bin/bash
######################################## #####
# Author zhao yanan
# Date 2010/08/23
# Update 2011/01/10
# Automatic detection and restart tomcat
######################################## #####
# The script can be written to an automatic task. the execution cycle can be determined based on the start and stop times of tomcat, as shown below. check every 10 minutes between and every day.
# Echo "*/10 0-20 **** root/script/tomcat_check.sh>/root/script/tomcat_check.log 2> & 1">/etc/crontab
Echo ===================================================== =
Date
Cd/root/script
Rm-f index.html # Delete the previously downloaded homepage
Wget-T 10-t 3-q http://XXX.XXX.XXX.XXX/index.html # Download the home page, after failure up to three times, each interval of 10 seconds
If [! -E index.html]; then # determines whether the homepage is successfully downloaded. If yes, the following task is executed; otherwise, the tasks after else are executed.
# Java Environment variables # set jdk Environment variables based on your actual situation
Export JAVA_HOME =/opt/jdk1.6.0 _ 21
Export CLASSPATH =.: $ JAVA_HOME/lib/tools. jar
Export CATALINA_HOME =/opt/apache-tomcat-6.0.26
Export PATH = $ JAVA_HOME/bin: $ PATH
Echo "restart tomcat ."
$ {CATALINA_HOME}/bin/shutdown. sh # Disable tomcat
Sleep 150 # wait for tomcat to close, usually 1 ~ S
Kill-9 'PS aux | grep java | grep-v grep | awk {print $2} '# force the tomcat process to end after the wait time ends.
Sleep 5
$ {CATALINA_HOME}/bin/startup. sh
Sleep 5 # wait for tomcat to start, usually 1 ~ S
/Usr/sbin/sendmail-t < From: web server # Mail sender. delete this comment during production.
To: username@gmail.com # master mail address, note, most mail receiving servers do not accept messages without fully-qualified, generally will fail, please delete this comment during production
Cc: username@gmail.com # Cc mail address, delete this comment during production
Subject: Alarm: tomcat restart # Mail title. delete this comment during production.
---------------------------------- # Email content. delete this comment during production.
In just restarted tomcat.
----------------------------------
EOF # There must be no space before this symbol. delete this comment during production.
Else
Echo "checked." # The home page is successfully downloaded, prompting you to check
Fi
The script file in the attachment contains the DOS line break (CR/LF). It is no problem to copy the content of the file to the SSH client. if the file is directly copied to the Linux system, run the following command first:
Mv example_tomcat_check.txt example_tomcat_check.sh
Dos2unix example_tomcat_check.sh
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