zoukankan      html  css  js  c++  java
  • Linux:看门狗watchdog.sh程序编写示例

    学习和借鉴前人经验,加之美化一番 

    1.  
      ###
    2.  
      # @Author: hanxiaoshun
    3.  
      # @Date: 2020-07-08 15:53:34
    4.  
      # @LastEditTime: 2020-09-05 10:54:45
    5.  
      # @LastEditors: Please set LastEditors
    6.  
      # @Description: In User Settings Edit
    7.  
      # @FilePath: shunziconfigowatchdog.sh
    8.  
      ###
    9.  
      #!/bin/sh
    10.  
      #kill -9 $(ps -ef|grep owatchdog.sh | grep -v grep | awk '{print $2}')
    11.  
      # 监控node 服务
    12.  
      chktask_node(){
    13.  
      #echo "check task name with" $1
    14.  
      pidcount=`ps -ef|grep $1 | grep -v grep |wc -l`
    15.  
      if [ $pidcount -eq 0 ]; then
    16.  
      #echo "no run"
    17.  
      node /home/shunzi/node/testServer.js > /dev/null 2>&1
    18.  
      echo "$CURTIME run $1 " >> /tmp/owatchdog_log.txt
    19.  
      fi
    20.  
      }
    21.  
      # 监控python server服务
    22.  
      chktask_python3(){
    23.  
      echo "check task name with" $1
    24.  
      pidcount=`ps -ef|grep $1 | grep -v grep | wc -l`
    25.  
      if [ $pidcount -eq 0 ]; then
    26.  
      python3 /home/shunzi/python/test_flask_server.py >/dev/null 2>&1 &
    27.  
      echo "$CURTIME run $1 " >> /tmp/owatchdog_log.txt
    28.  
      fi
    29.  
      }
    30.  
       
    31.  
      while true
    32.  
      do
    33.  
      CURTIME=`date "+%Y-%m-%d %H:%M:%S"`
    34.  
       
    35.  
      # 监控服务
    36.  
      if [ -d "/home/shunzi/python/" ]; then
    37.  
      cd/home/shunzi/python/
    38.  
      chktask_python3 test_flask_server.py
    39.  
      fi
    40.  
      if [ -d "/home/shunzi/node/" ]; then
    41.  
      cd /home/shunzi/node/
    42.  
      chktask_node testServer.js
    43.  
      fi
    44.  
       
    45.  
      # 监控脚本
    46.  
      #PID=`ps -ef|grep watch_test | grep -v grep | wc -l`
    47.  
      #if [ $PID -eq 0 ]; then
    48.  
      # if [ -f /usr/bin/watch_test.sh ]; then
    49.  
      # /usr/bin/watch_test.sh &
    50.  
      # fi
    51.  
      #fi
    52.  
       
    53.  
      # 监控命令行
    54.  
      count=`ps -ef|grep redis|grep -v grep|wc -l`
    55.  
      if [ $count -eq 0 ]; then
    56.  
      if [ -f /home/shunzi/redis_place/redis/local/redis/bin/redis-server ]; then
    57.  
      /home/vcontroller/redis_place/redis/local/redis/bin/redis-server /home/shunzi/redis_place/redis/local/redis/bin/redis.conf --daemonize yes --port 9673
    58.  
      fi
    59.  
      fi
    60.  
      sleep 3
    61.  
       
    62.  
      done
  • 相关阅读:
    haproxy常用配置
    分区命令(大于2TB的分区)
    css基础-2 div布局
    css基础-1
    2.HTML5基本标签
    1.HTML基本结构、头部、注释
    AWK数组
    nginx rewrite 基础
    nginx location详解
    Linux命令练习.ziw
  • 原文地址:https://www.cnblogs.com/lidabo/p/14004818.html
Copyright © 2011-2022 走看看