个人笔记
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 

1.7 KiB

看门狗脚本

已注册service程序看门狗

配置简单,但不够灵活

  • 脚本程序

    #!/bin/sh
    
    while [ 1 ]
    do
    	while read line
    	do
          if [ -n "$line" ] && [ ${line:0:1} != "#" ]
          then
              pm=$(service $line status)
    
              if [[ ${pm} =~ 'Not running' ]]
              then
                  echo "service $line start"
                  service $line start
              fi
    
          fi
    
    	done < /home/work/mengyxu/watchdog/service.cfg
    
    	sleep 10
    
    done
    
  • 配置文件

    #monitor
    whims
    location
    

可执行jar程序看门狗

可配置启动参数

  • 脚本程序

    #!/bin/sh
    
    while [ 1 ]
    do
            while read line
            do
                    if [ -n "$line" ] && [ ${line:0:1} != "#" ]
                    then
                            path=${line%/*}
                            pro=${line%% *}
                            par=${line#*.jar}
                            pm=$(ps -ef | grep java)
    
                            if [[ !($pm =~ $pro) ]]
                            then
                                    cd $path
                                    nohup java -server $par -jar $pro > /dev/null 2>&1 &
                                    echo "start $pro"
                            fi
    
                    fi
    
            done < /home/work/mengyxu/watchdog/jar.cfg
    
            sleep 10
    
    done
    
    
    
  • 配置文件

    #/home/work/mengyxu/monitor/monitor.jar
    /home/work/mengyxu/whims/whims.jar -Xms32m -Xmx128m
    /home/work/mengyxu/location/location.jar -Xms32m -Xmx64m
    

开机启动看门狗脚本

vim /etc/profile

在文件末尾添加

nohup /home/work/mengyxu/watchdog/jarWatch.sh > /dev/null 2>&1 &