2006-09-28 18:51:52 +00:00
|
|
|
#!/usr/bin/env php -q
|
2003-02-28 22:39:36 +00:00
|
|
|
<?php
|
2008-08-05 22:43:14 +00:00
|
|
|
// This file is part of BOINC.
|
|
|
|
// http://boinc.berkeley.edu
|
|
|
|
// Copyright (C) 2008 University of California
|
|
|
|
//
|
|
|
|
// BOINC is free software; you can redistribute it and/or modify it
|
|
|
|
// under the terms of the GNU Lesser General Public License
|
|
|
|
// as published by the Free Software Foundation,
|
|
|
|
// either version 3 of the License, or (at your option) any later version.
|
|
|
|
//
|
|
|
|
// BOINC is distributed in the hope that it will be useful,
|
|
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
|
|
|
// See the GNU Lesser General Public License for more details.
|
|
|
|
//
|
|
|
|
// You should have received a copy of the GNU Lesser General Public License
|
|
|
|
// along with BOINC. If not, see <http://www.gnu.org/licenses/>.
|
2003-02-28 22:39:36 +00:00
|
|
|
|
|
|
|
// watchdog script to ensure that the number of result records
|
|
|
|
// increases at least every X seconds (X = crontab period)
|
|
|
|
|
2009-10-02 18:32:40 +00:00
|
|
|
$cli_only = true;
|
2009-09-15 18:14:37 +00:00
|
|
|
include_once("util_ops.inc");
|
2003-02-28 22:39:36 +00:00
|
|
|
|
|
|
|
function fail($x) {
|
|
|
|
$f = fopen("error_log", "a");
|
|
|
|
if (!$f) return false;
|
|
|
|
fputs($f, "[".strftime("%T %D")."] ");
|
|
|
|
fputs($f, $x);
|
|
|
|
fclose($f);
|
|
|
|
exit();
|
|
|
|
}
|
|
|
|
|
|
|
|
function read_count_file() {
|
|
|
|
if (!file_exists("nresults")) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
$lines = file("nresults");
|
|
|
|
if (!$lines) return false;
|
2003-03-25 19:16:54 +00:00
|
|
|
return $lines;
|
2003-02-28 22:39:36 +00:00
|
|
|
}
|
|
|
|
|
2003-03-25 19:16:54 +00:00
|
|
|
function write_count_file($n,$m) {
|
2003-02-28 22:39:36 +00:00
|
|
|
$f = fopen("nresults", "w");
|
|
|
|
if (!$f) return false;
|
2003-06-14 20:03:08 +00:00
|
|
|
$x = sprintf("%d\n%d\n", $n, $m);
|
2003-02-28 22:39:36 +00:00
|
|
|
fwrite($f, $x);
|
|
|
|
fclose($f);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2003-03-25 19:16:54 +00:00
|
|
|
function get_working_count_from_db() {
|
|
|
|
$result = mysql_query("select count(*) from result where server_state = 4");
|
|
|
|
if (!$result) return false;
|
|
|
|
$count = mysql_fetch_array($result);
|
|
|
|
mysql_free_result($result);
|
|
|
|
return $count[0];
|
|
|
|
}
|
|
|
|
|
2003-02-28 22:39:36 +00:00
|
|
|
function get_count_from_db() {
|
|
|
|
$result = mysql_query("select count(*) from result");
|
|
|
|
if (!$result) return false;
|
|
|
|
$count = mysql_fetch_array($result);
|
|
|
|
mysql_free_result($result);
|
|
|
|
return $count[0];
|
|
|
|
}
|
|
|
|
|
|
|
|
$retval = db_init();
|
2003-03-06 19:53:32 +00:00
|
|
|
if ($retval != 0) {
|
|
|
|
fail("Can't open database\n");
|
2003-02-28 22:39:36 +00:00
|
|
|
}
|
|
|
|
$m = get_count_from_db();
|
|
|
|
if ($m == false) {
|
2003-03-06 19:53:32 +00:00
|
|
|
fail("Can't get result count from DB\n");
|
2003-02-28 22:39:36 +00:00
|
|
|
}
|
2003-03-25 19:16:54 +00:00
|
|
|
$p = get_working_count_from_db();
|
|
|
|
if ($p == false) {
|
|
|
|
fail("Can't get working result count from DB\n");
|
|
|
|
}
|
2003-02-28 22:39:36 +00:00
|
|
|
$n = read_count_file();
|
|
|
|
if ($n == false) {
|
2003-03-25 19:16:54 +00:00
|
|
|
write_count_file($m,$p);
|
2003-02-28 22:39:36 +00:00
|
|
|
exit();
|
|
|
|
}
|
2003-03-25 19:16:54 +00:00
|
|
|
if (trim($n[0]) == $m && trim($n[1]) == $p) {
|
2003-02-28 22:39:36 +00:00
|
|
|
fail("Result count hasn't changed\n");
|
|
|
|
}
|
2003-03-25 19:16:54 +00:00
|
|
|
write_count_file($m,$p);
|
2003-02-28 22:39:36 +00:00
|
|
|
|
|
|
|
?>
|