zoukankan      html  css  js  c++  java
  • java应用健康检查

    本文主要针对自己手写shell监控应用状态,有可系统解决方案的,比如K8S,可以略过

    #!/bin/sh
    #health_check.sh
    count
    =`ps -ef | grep test.jar | grep -v grep|wc -l` http_code=`curl -I -m 10 -o /dev/null -s -w %{http_code} http://127.0.0.1:8080/health/check` if [ ${count} -eq 0 ] ; then nohup java -jar /data/tomcat/test.jar >/dev/null 2>&1 elif [ ${http_code} -ne 200 ]; then /data/tomcat/restart.sh else echo "test process is running" fi

    restart.sh脚本内容:

    #!/bin/sh
    #restart.sh
    
    ps -ef |grep test.jar |awk '{print $2}'|xargs kill -9
    
    sleep 3
    
    nohup java -jar /data/tomcat/test.jar >/dev/null 2>&1 &
    note:
    在编写shell脚本时,遇到一下小坑,记录如下
    1.使用notepad++编写shell时,注意把文件的格式设置成UNIX,否则linux会不识某些字符,比如换行,以免造成不必要的困惑.
    2.本文以启动spring boot可执行jar包为例,使用nohup时,结尾要加上 >/dev/null 2>&1 &
    不然,启动日志会输出到jinkens里,显示不稳定(UNSTABLE)状态
    3.if/elif/else[]关键字符前后在留有空格
    

      

  • 相关阅读:
    HTML5 Input 类型
    Html5 web 储存
    解决json日期格式问题的3种方法(转载)
    Json格式串处理
    全局图片防盗链处理
    我的博客开张了
    iPhone手机屏幕分辨率
    通过CSS3伪类,美化Radio按钮样式
    测试用例 相关
    MongoDB基本命令
  • 原文地址:https://www.cnblogs.com/lixyu/p/9449715.html
Copyright © 2011-2022 走看看