-
Notifications
You must be signed in to change notification settings - Fork 73
/
kickRsyslog.php
executable file
·70 lines (56 loc) · 2.15 KB
/
kickRsyslog.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
#!/usr/bin/php
<?php
/**
* script to restart rsyslog if it appears to have stopped logging
* should be run via cron every minute
* also collects information about system state and mails it to addresses
*
* Copyright 2011 Jason Antman <[email protected]> <[email protected]>,
* on behalf of the taxpayers of the State of New Jersey and/or the students of Rutgers University,
* The State University of New Jersey.
*
* The latest version of this script can be found at:
* <https://github.com/jantman/misc-scripts/blob/master/kickRsyslog.php>
*
*/
require_once('collectRsyslogInfo.php');
$mail_to = array('[email protected]');
if(! file_exists(PID_FILE))
{
$host = trim(shell_exec("hostname"));
$subj = "RSYSLOG ERROR - Not running on $host";
$body = "ERROR - '".PID_FILE."' does not exist on host '$host'.\n\nSomeone should start rsyslogd, unless it is supposed to be stopped.\n\n";
$body .= "mail sent by ".__FILE__." on $host\n";
foreach($mail_to as $addr)
{
mail($addr, $subj, $body);
}
openlog("kickRsyslog.php", LOG_NDELAY | LOG_PERROR | LOG_PID, LOG_DAEMON);
syslog(LOG_EMERG, __FILE__." thinks rsyslog has died. If you actually see this log message in a file, the script is broken (rsyslog is actually running).");
closelog();
exit(1);
}
$mtime = filemtime(AGE_CHECK_FILE);
$age = time() - $mtime;
if($age >= THRESHOLD_SEC)
{
$body = collectRsyslogInfo(true, true);
$cmd = "/sbin/service rsyslog restart";
$host = trim(shell_exec("hostname"));
$start = microtime(true);
exec($cmd);
$foo = microtime(true) - $start;
$body .= "\nIssuing command '$cmd' as root.... ";
$body .= "Command ran in ".round($foo, 3)." seconds<br />";
$headers = "Content-type: text/html\r\n";
foreach($mail_to as $addr)
{
mail($addr, $subj, $body, $headers);
}
openlog("kickRsyslog.php", LOG_NDELAY | LOG_PERROR | LOG_PID, LOG_DAEMON);
syslog(LOG_EMERG, __FILE__." thinks rsyslog is hanging. If you actually see this log message in a file, the script is broken (rsyslog is actually running).");
closelog();
exit(1);
}
fwrite(STDERR, __FILE__." - rsyslog appears to be running normally.\n");
?>