类型 主要为定时和监控两种
方法 通过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 内容稍加改动理解 方便日后使用