類型 主要為定時和監控兩種
方法 通過http請求判斷tomcat是否處於啟動狀態 然后將路徑的tomcat進行啟動
代碼:
########################################### # author # date 2014/05/19 # update 2014/05/19 # Automatic detection and restart tomcat ############################################ echo ======================================== date cd /Users/yuzitao/Downloads/apache-tomcat-9.0.0.M22-web/bin/ rm -f main.jsp wget -T 10 -t 3 -q http://192.168.1.171:8081/index.jsp if [ ! -e main.jsp ]; then echo "restart tomcat." #export JAVA_HOME=/usr/local/java/jdk1.6.0_37 /Users/yuzitao/Downloads/apache-tomcat-9.0.0.M22-web/bin/shutdown.sh sleep 10 kill -9 `ps aux|grep "/Users/yuzitao/Downloads/apache-tomcat-9.0.0.M22-web/bin/"|grep -v grep|awk '{prin t $2}'` sleep 5 /Users/yuzitao/Downloads/apache-tomcat-9.0.0.M22-web/bin/startup.sh else echo "checked." fi
1、將代碼復制到monitor.sh中 放到相應路徑
2、給monitor.sh文件授權 sudo chmod a+x monitor.sh
3、設置定時任務 sudo crontab -e 添加 定時任務內容*/2 * * * * /Users/yuzitao/Downloads/apache-tomcat-9.0.0.M22-web/bin/monitor.sh 該腳本在全天范圍內沒兩分鍾執行一次
如在window環境下 需配置JAVA_HOME及jdk版本 (注掉部分)
ps:本文引自http://blog.csdn.net/InSpirit1/article/details/26343097 內容稍加改動理解 方便日后使用