#!/bin/sh # # This script is used to test watchdog functionality. WAITTIME=10 WDPID=0 WATCHDOG=`which watchdog` if [ "x$WATCHDOG" != "x" ]; then echo "PASS: watchdog found" else echo "FAIL: watchdog not found" exit 1 fi WATCHDOG_CONF=/etc/watchdog.conf if [ -f $WATCHDOG_CONF ]; then echo "PASS: watchdog config file found" sed -i '23,23 s/#//' $WATCHDOG_CONF else echo "FAIL: watchdog config file not found" exit 1 fi # kill any previous instance of watchdog (pkill may be used as well) for wpid in `ps ax | grep $WATCHDOG | grep -v grep | awk -e '{print $1}'` ; do kill -KILL $wpid done # wait until all processes are gone for wt in `seq 1 $WAITTIME ` ; do sleep 1 wd_running=`ps ax | grep $WATCHDOG | grep -v grep | awk -e '{print $1}'` if [ -z $wd_running ] ; then break fi done if [ $wt -ge $WAITTIME ] ; then echo "FAIL: Failed to stop the watchdog daemon" exit 1 fi # start a fresh watchdog $WATCHDOG -v /dev/watchdog # wait up to $WAITTIME seconds for the process to start for wt in `seq 1 $WAITTIME ` ; do sleep 1 wd_running=`ps ax | grep $WATCHDOG | grep -v grep | awk -e '{print $1}'` if [ ! -z $wd_running ] ; then WDPID=$wd_running echo "PASS: Watchdog daemon started successfully [$WDPID]" break fi echo $wt done if [ $wt -ge $WAITTIME ] ; then echo "FAIL: Failed to start watchdog daemon" exit 1 fi logmsg_test() { WDCOUNTER1=`cat /var/log/messages | grep watchdog | grep $WDPID | wc -l` sleep 5 WDCOUNTER2=`cat /var/log/messages | grep watchdog | grep $WDPID | wc -l` if [ $WDCOUNTER2 -gt $WDCOUNTER1 ] ; then return 0 fi return 1 } exit_code=1 # test is performed 2 times because logrotate may step in during those 5sec if logmsg_test || logmsg_test ; then echo "PASS: Watchdog is alive" kill -KILL $WDPID > /dev/null 2>&1 exit_code=0 else echo "FAIL: Watchdog is not working" kill -KILL $WDPID > /dev/null 2>&1 exit_code=1 fi kill -KILL $WDPID > /dev/null 2>&1 exit $exit_code