zoukankan      html  css  js  c++  java
  • CentOS服务器上监控tomcat,如果挂掉则重启

    该脚本用于监控tomcat服务器是否可用,如果服务不可用则重启tomcat

    略微修改后也可以用于其他服务的监控

    monitor.sh 脚本如下

     1 #!/bin/sh
     2 
     3 
     4 # 定义要监控的页面地址
     5 WebUrl="http://xxxxxxx.com"
     6 GetPageInfo=/dev/null
     7 
     8 
     9 while [ "1" = "1" ]
    10 do
    11 
    12 TomcatServiceCode=$(curl -s -o $GetPageInfo -m 10 --connect-timeout 10 $WebUrl -w %{http_code})
    13 echo "`date "+%Y-%m-%d %H:%M:%S"` : TomcatServiceCode:"$TomcatServiceCode
    14 
    15 #如果返回不是http 200 ,说明tomcat已经挂断
    16 #需要杀掉进程,并重启tomcat
    17   if [ $TomcatServiceCode -eq 200 ];then
    18      echo "`date "+%Y-%m-%d %H:%M:%S"` :tomcat is okay."
    19   else
    20     ID=`ps -ef | grep tomcat | grep -v "grep" | awk '{print $2}'`
    21     echo $ID    
    22     for id in $ID
    23     do
    24      kill -9 $id
    25      echo "`date "+%Y-%m-%d %H:%M:%S"` : killed $id"
    26     done
    27     echo "`date "+%Y-%m-%d %H:%M:%S"` : PID have been killed"
    28     echo "`date "+%Y-%m-%d %H:%M:%S"` : begin to restart the tomcat."
    29     service tomcat start
    30     echo "`date "+%Y-%m-%d %H:%M:%S"` : tomcat have been restarted."
    31   fi
    32 echo "check done."
    33 echo "`date "+%Y-%m-%d %H:%M:%S"` sleep 60s and wait next check.."
    34 sleep 60s 
    35 done

    启动脚本

    nohup ./monitor.sh >/dev/null 2>&1 

  • 相关阅读:
    strict aliasing
    加密数据包加解密部分逆向跟踪
    自定义session扫描器
    同步容器类ConcurrentHashMap及CopyOnWriteArrayList
    CountDownLatch闭锁
    volatile关键字与内存可见性
    原子变量与CAS算法
    C语言笔记一
    小组讨论4
    201920201学期 20192416《网络空间安全专业导论》第六周学习总结
  • 原文地址:https://www.cnblogs.com/DevinZhang1990/p/12162214.html
Copyright © 2011-2022 走看看