Shell监控Tomcat并启动

Shell代码
  1. #!/bin/sh  
  2.   
  3. export _JAVA_SR_SIGNUM=12  
  4. export JAVA_HOME=/usr/java/jdk1.6.0_11  
  5. export CATALINA_BASE=/home/co_newest_family/tomcat  
  6. export CATALINA_HOME=/usr/local/apache-tomcat-6.0.18  
  7. export LD_LIBRARY_PATH=:/usr/local/lib/:/usr/local/apr/lib/:/usr/local/apr/lib/  
  8. 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"  
  9. export PATH=$JAVA_HOME/bin:$PATH:$HOME/bin  
  10.   
  11. date=`date "+%H:%M:%S"`  
  12. message="$date|check_tomcat(81_co_newest_family)_shutdown_and_restart_it."  
  13. request_url="http://192.168.5.35:9091/index.jsp"  
  14.   
  15. if ! wget -t1 -T2 $request_url &> /dev/null;then  
  16.    #pid=`ps aux | grep "\-Dcms4.home\=\/home\/co_newest_family\/"| awk '{print $2}'`          
  17.    #kill -9 $pid  
  18.    ps x|grep 'tomcat'|grep -v 'grep'|grep -v 'sh'|awk '{print $1}'|xargs kill -9  
  19.    $CATALINA_HOME/bin/startup.sh  
  20.    wget -t1 -T2 http://192.168.5.33:8880/send.jsp?msg=$message &> /dev/null;  
  21.    echo "$date check tomcat shutdown and restart it." >> logs/check.log  
  22. else  
  23.    echo "$date check tomcat ok." >> logs/check.log  
  24. fi  
  25.   
  26. rm -f index.jsp*  
  27. rm -f send.jsp?msg=* 
  28. 备注:定时监控tomcat,发现挂掉,立刻重启!并发送短信
    -t1 表示只请求一次 
    -T2 表示2秒超时 
posted @ 2015-05-21 11:34  junxing  阅读(360)  评论(0)    收藏  举报