# 看门狗脚本 ## 已注册service程序看门狗 配置简单,但不够灵活 - 脚本程序 ```shell #!/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 ``` - 配置文件 ```txt #monitor whims location ``` ## 可执行jar程序看门狗 可配置启动参数 - 脚本程序 ```shell #!/bin/sh #!/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 ``` - 配置文件 ```txt #/home/work/mengyxu/monitor/monitor.jar /home/work/mengyxu/whims/whims.jar -Xms32m -Xmx128m /home/work/mengyxu/location/location.jar -Xms32m -Xmx64m ```