Shell监控Tomcat并启动
Shell代码
- #!/bin/sh
- export _JAVA_SR_SIGNUM=12
- export JAVA_HOME=/usr/java/jdk1.6.0_11
- export CATALINA_BASE=/home/co_newest_family/tomcat
- export CATALINA_HOME=/usr/local/apache-tomcat-6.0.18
- export LD_LIBRARY_PATH=:/usr/local/lib/:/usr/local/apr/lib/:/usr/local/apr/lib/
- export CATALINA_OPTS="-server -Xms1024m -Xmx2048m -XX:PermSize=128m -XX:MaxPermSize=128m -Dcom.sun.management.jmxremote -Dcom.sun.management.jmxremote.port=9158 -Dcom.sun.management.jmxremote.authenticate=false -Dcom.sun.management.jmxremote.ssl=false -Dfile.encoding=UTF8 -Dmeganotes.home=/home/co_newest_family"
- export PATH=$JAVA_HOME/bin:$PATH:$HOME/bin
- date=`date "+%H:%M:%S"`
- message="$date|check_tomcat(81_co_newest_family)_shutdown_and_restart_it."
- request_url="http://192.168.5.35:9091/index.jsp"
- if ! wget -t1 -T2 $request_url &> /dev/null;then
- #pid=`ps aux | grep "\-Dcms4.home\=\/home\/co_newest_family\/"| awk '{print $2}'`
- #kill -9 $pid
- ps x|grep 'tomcat'|grep -v 'grep'|grep -v 'sh'|awk '{print $1}'|xargs kill -9
- $CATALINA_HOME/bin/startup.sh
- wget -t1 -T2 http://192.168.5.33:8880/send.jsp?msg=$message &> /dev/null;
- echo "$date check tomcat shutdown and restart it." >> logs/check.log
- else
- echo "$date check tomcat ok." >> logs/check.log
- fi
- rm -f index.jsp*
- rm -f send.jsp?msg=*
- 备注:定时监控tomcat,发现挂掉,立刻重启!并发送短信
-t1 表示只请求一次
-T2 表示2秒超时

浙公网安备 33010602011771号