• checkAPP


    [root@BMS001 opt]# cat /opt/checkApp.sh
    #!/bin/bash

    . /etc/profile

    LOG_FILE="/opt/app_monitor.log"
    RET=0


    APP_NAME="/opt/bms_pc_7061"
    PORT_NAME="7061"

    echo '######################################### $APP_NAME  MONITOR ###################################' >> ${LOG_FILE}
    NUM1=`ps -ef| grep -w ${APP_NAME} |grep -v grep| wc -l`

    /usr/bin/nc -v -z -w2 192.168.50.230 7061
    if  test $? -eq 0 && [ "$NUM1" -eq "1" ] ;then
      echo "`date` $APP_NAME  is live" >> ${LOG_FILE}
    else
      RET=1
      echo "`date` $APP_NAME  is death"
      /bin/su - unify_bms -c "leo stop /opt/bms_pc_7061"
     
      sleep 2
      ps -ef | grep -w ${APP_NAME} | grep -v grep | awk '{print $2}' | xargs kill -9 >/dev/null 2>&1
      sleep 3
       /bin/su - unify_bms -c "leo start /opt/bms_pc_7061"
      echo "`date` $APP_NAME restart  finished." >> ${LOG_FILE}
    fi

    echo '######################################### $APP_NAME FINISHED ######################################' >> ${LOG_FILE}
    APP_NAME="/opt/bms_pc_7062"
    PORT_NAME="7062"

    echo '######################################### $APP_NAME  MONITOR ##############
    ######################' >> ${LOG_FILE}
    NUM1=`ps -ef| grep -w ${APP_NAME} |grep -v grep| wc -l`

    /usr/bin/nc -v -z -w2 192.168.50.230 7062
    if  test $? -eq 0 && [ "$NUM1" -eq "1" ] ;then
      echo "`date` $APP_NAME  is live" >> ${LOG_FILE}
    else
      RET=1
      echo "`date` $APP_NAME  is death"
      /bin/su - unify_bms -c "leo stop /opt/bms_pc_7062"

      sleep 2
      ps -ef | grep -w ${APP_NAME} | grep -v grep | awk '{print $2}' | xargs kill -9 >/dev/null 2>&1
      sleep 3
       /bin/su - unify_bms -c "leo start /opt/bms_pc_7062"
      echo "`date` $APP_NAME restart  finished." >> ${LOG_FILE}
    fi

    echo '######################################### $APP_NAME FINISHED ##############
    #########################' >> ${LOG_FILE}
    APP_NAME="/opt/bms_pc_adapter_7021"
    PORT_NAME="7021"

    echo '######################################### $APP_NAME  MONITOR ##############
    #
    ######################' >> ${LOG_FILE}
    NUM1=`ps -ef| grep -w ${APP_NAME} |grep -v grep| wc -l`

    /usr/bin/nc -v -z -w2 192.168.50.230 7021
    if  test $? -eq 0 && [ "$NUM1" -eq "1" ] ;then
      echo "`date` $APP_NAME  is live" >> ${LOG_FILE}
    else
      RET=1
      echo "`date` $APP_NAME  is death"
      /bin/su - unify_bms -c "leo stop /opt/bms_pc_adapter_7021"

      sleep 2
      ps -ef | grep -w ${APP_NAME} | grep -v grep | awk '{print $2}' | xargs kill -9  >/dev/null 2>&1
      sleep 3
       /bin/su - unify_bms -c "leo start /opt/bms_pc_adapter_7021"
      echo "`date` $APP_NAME restart  finished." >> ${LOG_FILE}
    fi

    echo '######################################### $APP_NAME FINISHED ##############
    #
    #########################' >> ${LOG_FILE}
    APP_NAME="/opt/bms_pc_adapter_7022"
    PORT_NAME="7022"

    echo '######################################### $APP_NAME  MONITOR ##############
    #
    #
    ######################' >> ${LOG_FILE}
    NUM1=`ps -ef| grep -w ${APP_NAME} |grep -v grep| wc -l`

    /usr/bin/nc -v -z -w2 192.168.50.230 7022
    if  test $? -eq 0 && [ "$NUM1" -eq "1" ] ;then
      echo "`date` $APP_NAME  is live" >> ${LOG_FILE}
    else
      RET=1
      echo "`date` $APP_NAME  is death"
      /bin/su - unify_bms -c "leo stop /opt/bms_pc_adapter_7022"

      sleep 2
      ps -ef | grep -w ${APP_NAME} | grep -v grep | awk '{print $2}' | xargs kill -9 >/dev/null 2>&1
      sleep 3
       /bin/su - unify_bms -c "leo start /opt/bms_pc_adapter_7022"
      echo "`date` $APP_NAME restart  finished." >> ${LOG_FILE}
    fi

    echo '######################################### $APP_NAME FINISHED ##############
    #
    #
    #########################' >> ${LOG_FILE}
    APP_NAME="/opt/bms3a_7001"
    PORT_NAME="7001"

    echo '######################################### $APP_NAME  MONITOR ##############
    #
    ######################' >> ${LOG_FILE}
    NUM1=`ps -ef| grep -w ${APP_NAME} |grep -v grep| wc -l`

    /usr/bin/nc -v -z -w2 192.168.50.230 7001
    if  test $? -eq 0 && [ "$NUM1" -eq "1" ] ;then
      echo "`date` $APP_NAME  is live" >> ${LOG_FILE}
    else
      RET=1
      echo "`date` $APP_NAME  is death"
      /bin/su - unify_bms -c "leo stop /opt/bms3a_7001"

      sleep 2
      ps -ef | grep -w ${APP_NAME} | grep -v grep | awk '{print $2}' | xargs kill -9  >/dev/null 2>&1
      sleep 3
       /bin/su - unify_bms -c "leo start /opt/bms3a_7001"
      echo "`date` $APP_NAME restart  finished." >> ${LOG_FILE}
    fi

    echo '######################################### $APP_NAME FINISHED ##############
    #
    #########################' >> ${LOG_FILE}
    APP_NAME="/opt/bms3a_7002"
    PORT_NAME="7002"

    echo '######################################### $APP_NAME  MONITOR ##############
    #
    #
    ######################' >> ${LOG_FILE}
    NUM1=`ps -ef| grep -w ${APP_NAME} |grep -v grep| wc -l`

    /usr/bin/nc -v -z -w2 192.168.50.230 7002
    if  test $? -eq 0 && [ "$NUM1" -eq "1" ] ;then
      echo "`date` $APP_NAME  is live" >> ${LOG_FILE}
    else
      RET=1
      echo "`date` $APP_NAME  is death"
      /bin/su - unify_bms -c "leo stop /opt/bms3a_7002"

      sleep 2
      ps -ef | grep -w ${APP_NAME} | grep -v grep | awk '{print $2}' | xargs kill -9 >/dev/null 2>&1
      sleep 3
       /bin/su - unify_bms -c "leo start /opt/bms3a_7002"
      echo "`date` $APP_NAME restart  finished." >> ${LOG_FILE}
    fi

    echo '######################################### $APP_NAME FINISHED ##############
    #
    #
    #########################' >> ${LOG_FILE}
    exit $RET

  • 相关阅读:
    [前端插件]Bootstrap Table服务器分页与在线编辑应用总结
    Accord.NET_Naive Bayes Classifier
    Accord.NET入门
    [C++]STL容器Vector的内存释放
    [设计模式]适配器模式与外观模式
    [设计模式]工厂模式
    Linux下spi驱动开发
    Qt移植对USB鼠标键盘、触摸屏的支持
    linux设备模型详解 http://blog.csdn.net/linux_xiaomugua/article/details/6989386
    LGPL协议的理解
  • 原文地址:https://www.cnblogs.com/lubing666666/p/4366104.html
Copyright © 2020-2023  润新知