Hello Guys,
I'm trying to write a small script that does a check to ensure an application hasnt frozen for my watchdog timer. The script needs to return a brinary 0 if all is fine, and 1 if there is a problem.
I'm not sure of the best way to check that the application hasnt frozen, but at the moment I have the application writing to a file every 10 seconds or so, so I'm thinking I can compare the current system time against the time the file was last modified, and if the tollerance exceeds 30 seconds or so then return 1.
I'm a little bit lost on how to achieve this, but Ive made a rough start on the script below.
The idea is that if the application has frozen, then it terminates the process, before restarting it. It can then retest it, if it fails this second time then it returns 1, the watchdog would then reboot the system.
There may be better ways to do this, I'm just not sure, hence this post. The goal of the script is to check if the application has frozen, and if it has, restart it, if it wont restart properly, then reboot the system.
Thanks for any help guys,
Rob
I'm trying to write a small script that does a check to ensure an application hasnt frozen for my watchdog timer. The script needs to return a brinary 0 if all is fine, and 1 if there is a problem.
I'm not sure of the best way to check that the application hasnt frozen, but at the moment I have the application writing to a file every 10 seconds or so, so I'm thinking I can compare the current system time against the time the file was last modified, and if the tollerance exceeds 30 seconds or so then return 1.
I'm a little bit lost on how to achieve this, but Ive made a rough start on the script below.
The idea is that if the application has frozen, then it terminates the process, before restarting it. It can then retest it, if it fails this second time then it returns 1, the watchdog would then reboot the system.
Code:
#! /bin/sh
lastalive=`stat -c %Y Logs/Alive.log`
currenttime=`date +%s`
echo $lastalive
echo $currenttime
amount=$(($currenttime - $lastalive))
echo $amount
if [ "$amount" < 30 ];
then
echo 'Application Fine'
# Return 0 as the application appears to be running fine.
else
echo 'Application Frozen'
# I want to terminate the appliaction here, and then restart it, then perform the check it again, only if it fails the seconds test should it return 1.
fi
There may be better ways to do this, I'm just not sure, hence this post. The goal of the script is to check if the application has frozen, and if it has, restart it, if it wont restart properly, then reboot the system.
Thanks for any help guys,
Rob