Issues (1963)

html/ops/watchdogs.php (2 issues)

1
#! /usr/bin/env php
2
<?php
3
// This file is part of BOINC.
4
// http://boinc.berkeley.edu
5
// Copyright (C) 2008 University of California
6
//
7
// BOINC is free software; you can redistribute it and/or modify it
8
// under the terms of the GNU Lesser General Public License
9
// as published by the Free Software Foundation,
10
// either version 3 of the License, or (at your option) any later version.
11
//
12
// BOINC is distributed in the hope that it will be useful,
13
// but WITHOUT ANY WARRANTY; without even the implied warranty of
14
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
15
// See the GNU Lesser General Public License for more details.
16
//
17
// You should have received a copy of the GNU Lesser General Public License
18
// along with BOINC.  If not, see <http://www.gnu.org/licenses/>.
19
20
// General-purpose watchdog script.
21
// Run this from crontab.
22
// We use the mod time of a file "watchdog_exec_time"
23
// to keep track of the last time we ran.
24
25
// BOINC uses a number of "error log files".
26
// If any error log file has been updated since the last time we ran,
27
// sound the alarm.
28
29
// TODO: to detect file system full errors,
0 ignored issues
show
Coding Style Best Practice introduced by
Comments for TODO tasks are often forgotten in the code; it might be better to use a dedicated issue tracker.
Loading history...
30
// have this program attempt to create/read a file.
31
32
$cli_only = true;
33
require_once("../inc/util_ops.inc");
34
35
function sound_alarm($x) {
36
    //echo "alarm: $x\n";
37
    mail(SYS_ADMIN_EMAIL, "BOINC problem", $x);
38
}
39
40
function check_log_file($file, $last_time) {
41
    $t = filemtime($file);
42
    if ($t == false) {
0 ignored issues
show
Bug Best Practice introduced by
It seems like you are loosely comparing $t of type integer to the boolean false. If you are specifically checking for 0, consider using something more explicit like === 0 instead.
Loading history...
43
        sound_alarm("log file ".$file." missing");
44
    } else if ($t > $last_time) {
45
        $lines = file($file);
46
        $last_line = $lines[count($lines)-1];
47
        sound_alarm($last_line);
48
    }
49
}
50
51
    $last_time = filemtime("watchdog_exec_time");
52
    if (!$last_time) {
53
        sound_alarm("Couldn't find watchdog_exec_time");
54
    }
55
    touch("watchdog_exec_time");
56
57
    check_log_file("error_log", $last_time);
58
?>
59