diff options
Diffstat (limited to 'modules-available/rebootcontrol/hooks/cron.inc.php')
-rw-r--r-- | modules-available/rebootcontrol/hooks/cron.inc.php | 22 |
1 files changed, 13 insertions, 9 deletions
diff --git a/modules-available/rebootcontrol/hooks/cron.inc.php b/modules-available/rebootcontrol/hooks/cron.inc.php index 67e17c83..289426c7 100644 --- a/modules-available/rebootcontrol/hooks/cron.inc.php +++ b/modules-available/rebootcontrol/hooks/cron.inc.php @@ -5,15 +5,18 @@ */ if (in_array((int)date('G'), [6, 7, 9, 12, 15]) && in_array(date('i'), ['00', '01', '02', '03'])) { $res = Database::simpleQuery('SELECT hostid, host, port, username, sshkey, script FROM reboot_jumphost'); - while ($row = $res->fetch(PDO::FETCH_ASSOC)) { + foreach ($res as $row) { RebootControl::wakeViaJumpHost($row, '255.255.255.255', [['macaddr' => '00:11:22:33:44:55']]); } } +// CRON for Scheduler +Scheduler::cron(); + /* * Client reachability test -- can be disabled */ -if (mt_rand(1, 2) !== 1 || Property::get(RebootControl::KEY_AUTOSCAN_DISABLED)) +if (Property::get(RebootControl::KEY_AUTOSCAN_DISABLED)) return; class Stuff @@ -21,7 +24,7 @@ class Stuff public static $subnets; } -function destSawPw($destTask, $destMachine, $passwd) +function destSawPw(array $destTask, array $destMachine, string $passwd): bool { return strpos($destTask['data']['result'][$destMachine['machineuuid']]['stdout'], "passwd=$passwd") !== false; } @@ -137,7 +140,7 @@ function resultToTime($result) $next = 86400 * 7; // a week } else { // Test finished, reachable - $next = 86400 * 30; // a month + $next = 86400 * 14; // two weeks } return time() + round($next * mt_rand(90, 133) / 100); } @@ -147,12 +150,12 @@ function resultToTime($result) */ // First, cleanup: delete orphaned subnets that don't exist anymore, or don't have any clients using our server -$cutoff = strtotime('-180 days'); +$cutoff = strtotime('-720 days'); Database::exec('DELETE FROM reboot_subnet WHERE fixed = 0 AND lastseen < :cutoff', ['cutoff' => $cutoff]); // Get machines running, group by subnet $cutoff = time() - 301; // Really only the ones that didn't miss the most recent update -$res = Database::simpleQuery("SELECT s.subnetid, s.end AS bcast, m.machineuuid, m.clientip, m.macaddr +$res = Database::simpleQuery("SELECT s.subnetid, s.end AS bcast, m.machineuuid, m.clientip, m.macaddr, m.locationid FROM reboot_subnet s INNER JOIN machine m ON ( (m.state = 'IDLE' OR m.state = 'OCCUPIED') @@ -168,12 +171,13 @@ if ($res->rowCount() === 0) return; Stuff::$subnets = []; -while ($row = $res->fetch(PDO::FETCH_ASSOC)) { +foreach ($res as $row) { if (!isset(Stuff::$subnets[$row['subnetid']])) { Stuff::$subnets[$row['subnetid']] = []; } Stuff::$subnets[$row['subnetid']][] = $row; } +unset($res); $task = Taskmanager::submit('DummyTask', []); $task = Taskmanager::waitComplete($task, 4000); @@ -191,7 +195,7 @@ $res = Database::simpleQuery("SELECT subnetid FROM reboot_subnet WHERE subnetid IN (:active) AND nextdirectcheck < UNIX_TIMESTAMP() AND fixed = 0 ORDER BY nextdirectcheck ASC LIMIT 10", ['active' => array_keys(Stuff::$subnets)]); cron_log('Direct checks: ' . $res->rowCount() . ' (' . implode(', ', array_keys(Stuff::$subnets)) . ')'); -while ($row = $res->fetch(PDO::FETCH_ASSOC)) { +foreach ($res as $row) { $dst = (int)$row['subnetid']; cron_log('Direct check for subnetid ' . $dst); $result = testServerToClient($dst); @@ -236,7 +240,7 @@ if (count($combos) > 0) { ORDER BY sxs.nextcheck ASC LIMIT 10", ['combos' => $combos]); cron_log('C2C checks: ' . $res->rowCount()); - while ($row = $res->fetch(PDO::FETCH_ASSOC)) { + foreach ($res as $row) { $src = (int)$row['srcid']; $dst = (int)$row['dstid']; $result = testClientToClient($src, $dst); |