我解决了这个使用看门狗脚本来检查直接(grep的),如果项目(S)是(是)运行。通过每分钟(从Ubuntu下的cron)调用看门狗,我基本上保证(程序和环境非常稳定),没有程序将保持脱机超过59秒。
该脚本将检查在阵列中使用名称的节目列表,看看每一个正在运行,并且,在没有的情况下,启动它。
#!/bin/bash
#
# watchdog
#
# Run as a cron job to keep an eye on what_to_monitor which should always
# be running. Restart what_to_monitor and send notification as needed.
#
# This needs to be run as root or a user that can start system services.
#
# Revisions: 0.1 (20100506), 0.2 (20100507)
# first prog to check
NAME[0]=soc_gt2
# 2nd
NAME[1]=soc_gt0
# 3rd, etc etc
NAME[2]=soc_gp00
# START=/usr/sbin/$NAME
[email protected]
[email protected]
GREP=/bin/grep
PS=/bin/ps
NOP=/bin/true
DATE=/bin/date
MAIL=/bin/mail
RM=/bin/rm
for nameTemp in "${NAME[@]}"; do
$PS -ef|$GREP -v grep|$GREP $nameTemp >/dev/null 2>&1
case "$?" in
0)
# It is running in this case so we do nothing.
echo "$nameTemp is RUNNING OK. Relax."
$NOP
;;
1)
echo "$nameTemp is NOT RUNNING. Starting $nameTemp and sending notices."
START=/usr/sbin/$nameTemp
$START 2>&1 >/dev/null &
NOTICE=/tmp/watchdog.txt
echo "$NAME was not running and was started on `$DATE`" > $NOTICE
# $MAIL -n -s "watchdog notice" -c $NOTIFYCC $NOTIFY < $NOTICE
$RM -f $NOTICE
;;
esac
done
exit
我不使用日志验证,尽管你可以很容易地整合到这一点你自己的版本(只是改变grep命令日志检查,例如)。
,如果你从命令行运行它(或腻子,如果你是远程连接),你会看到什么是工作,什么wasnt。几个月来一直在使用它,而不会出现呃逆。只要你想看看工作是什么(不管它在cron下运行)就可以调用它。
您也可以将您的所有关键项目一个文件夹中,做一个目录列表,并检查该文件夹中的每个文件都以相同的名称运行的程序。或者逐行读取一个txt文件,每一行对应一个应该运行的程序。 etcetcetc