虽然在一台服务器上安装了若干个Tomcat,保证了网站的顺利运行,但随之而来带来的一个问题就是,当其中某个Tomcat 崩溃时,需要对其进行重启。由于重启的Shell代码已经有了,不过就是只能启动一个Tomcat,所以对以前的Shell代码进行了修改,使其支持对多个Tomcat的重启。
脚本
相关的脚本如下所示:
#!/bin/ksh log=/var/log/tomcat_web/tomcatrun-logthome=/usr/local/tomcat ip="192.168.1.35" port="8085" cluster="192.168.1.35:8080|tomcat1 192.168.1.35:8085|tomcat2" for server in $cluster do echo "$server"|while IFS="|" read f1 f2 do host="$f1" servicename="$f2" result=`/usr/bin/wget -S --spider --tries=3 --timeout=3 http://$host/blank/word.jsp 2>&1 | grep HTTP/1.1|awk '{print $2}'` if [ "$result" = "200" ] then echo "Tomcat $host $servicename Running OK" else sleep 5 result=`/usr/bin/wget -S --spider --tries=5 --timeout=3 http://$host/blank/word.jsp 2>&1 | grep HTTP/1.1|awk '{print $2}'` if [ "$result" = "200" ] then echo "Tomcat $host $servicename Running OK" else echo "Tomcat $host $servicename is not runnng : `date +%Y/%m/%d-%H:%M:%S`" service $servicename start echo "Tomcat $host $servicename restart finish." fi fi done done