2006-09-28 18:01:29 +00:00
|
|
|
#! /usr/bin/php
|
2003-02-28 22:39:36 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
// General-purpose watchdog script.
|
|
|
|
// Run this from crontab.
|
|
|
|
// We use the mod time of a file "watchdog_exec_time"
|
|
|
|
// to keep track of the last time we ran.
|
|
|
|
|
|
|
|
// BOINC uses a number of "error log files".
|
|
|
|
// If any error log file has been updated since the last time we ran,
|
|
|
|
// sound the alarm.
|
|
|
|
|
|
|
|
// TODO: to detect file system full errors,
|
|
|
|
// have this program attempt to create/read a file.
|
|
|
|
|
|
|
|
function sound_alarm($x) {
|
2003-03-05 23:44:24 +00:00
|
|
|
//echo "alarm: $x\n";
|
2006-06-06 18:45:40 +00:00
|
|
|
mail(SYS_ADMIN_EMAIL, "BOINC problem", $x);
|
2003-02-28 22:39:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function check_log_file($file, $last_time) {
|
|
|
|
$t = filemtime($file);
|
|
|
|
if ($t == false) {
|
|
|
|
sound_alarm("log file ".$file." missing");
|
|
|
|
} else if ($t > $last_time) {
|
|
|
|
$lines = file($file);
|
|
|
|
$last_line = $lines[count($lines)-1];
|
|
|
|
sound_alarm($last_line);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
$last_time = filemtime("watchdog_exec_time");
|
|
|
|
if (!$last_time) {
|
2003-03-06 19:53:32 +00:00
|
|
|
sound_alarm("Couldn't find watchdog_exec_time");
|
2003-02-28 22:39:36 +00:00
|
|
|
}
|
|
|
|
touch("watchdog_exec_time");
|
|
|
|
|
|
|
|
check_log_file("error_log", $last_time);
|
|
|
|
?>
|