-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathhealth_check.php
69 lines (58 loc) · 2.32 KB
/
health_check.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
<?php
namespace CluebotNG;
/*
* Copyright (C) 2015 Jacobi Carter and Chris Breneman
*
* This file is part of ClueBot NG.
*
* ClueBot NG is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 2 of the License, or
* (at your option) any later version.
*
* ClueBot NG 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 General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with ClueBot NG. If not, see <http://www.gnu.org/licenses/>.
*/
/* Stripped down setup logic */
date_default_timezone_set('Europe/London');
include 'vendor/autoload.php';
$logger = new \Monolog\Logger('cluebotng');
$logger->pushHandler(new \Monolog\Handler\StreamHandler('php://stderr', \Monolog\Logger::INFO));
require_once 'cluebot-ng.config.php';
require_once 'api.php';
if (Config::$pass == null) {
Config::$pass = trim(file_get_contents(getenv('HOME') . '/.cluebotng.bot.password'));
}
/* Configure API access */
Api::init($logger);
if (!Api::$a->login(Config::$user, Config::$pass)) {
$logger->addError('Failed to authenticate with wikipedia');
exit(1);
}
/* Get our last edit time */
$usercontribs = Api::$a->usercontribs(Config::$user, 1);
if (count($usercontribs) != 1) {
$logger->addError('Failed to find usercontribs for ' . $Config::$user);
exit(1);
}
$last_contrib_timestamp = $usercontribs[0]['timestamp'];
/* If we edited in the last 15min, then all good */
if (strtotime($last_contrib_timestamp) > (time() - 900)) {
$logger->addInfo('Last contribution was within last 15min (' . $last_contrib_timestamp . ')');
exit(0);
}
/* Get out uptime, since this is for a container, just check the 'init' pid */
$current_uptime = filemtime("/proc/1");
/* If we have been running for less than 30min, then all good (back off) */
if ($current_uptime > (time() - 1800)) {
$logger->addInfo('Uptime less than 30min (' . $current_uptime . ')');
exit(0);
}
/* Otherwise, we need to die */
$logger->addError('Are you death or paradise? ' . $last_contrib_timestamp . ' / ' . $current_uptime);
exit(1);