From bc09d8c59af1ac9e0eddb4f40f03ab02b5849d88 Mon Sep 17 00:00:00 2001 From: Christian Hofmaier Date: Tue, 23 Feb 2021 21:03:50 +0100 Subject: [rebootcontrol] add Scheduler Cron Job --- modules-available/rebootcontrol/hooks/cron.inc.php | 23 ++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/modules-available/rebootcontrol/hooks/cron.inc.php b/modules-available/rebootcontrol/hooks/cron.inc.php index 67e17c83..c80a87b1 100644 --- a/modules-available/rebootcontrol/hooks/cron.inc.php +++ b/modules-available/rebootcontrol/hooks/cron.inc.php @@ -10,6 +10,29 @@ if (in_array((int)date('G'), [6, 7, 9, 12, 15]) && in_array(date('i'), ['00', '0 } } +// CRON for Scheduler +$now = time(); +$res = Database::simpleQuery("SELECT * FROM reboot_scheduler WHERE nextexecution < :now", ['now' => $now]); +while ($row = $res->fetch(PDO::FETCH_ASSOC)) { + + // Calculate next_execution for the event. + $location = Database::queryFirst("SELECT openingtime FROM `location` WHERE locationid = :lid", array('lid' => $row['locationid'])); + Scheduler::updateSchedule($row['locationid'], $row['action'], $row['options'], $location['openingtime']); + + if ($row['nextexecution'] + 1200 < $now) continue; + + $machinedb = Database::simpleQuery("SELECT machineuuid, clientip, macaddr, locationid FROM machine WHERE locationid = :locid", ['locid' => $row['locationid']]); + $machines = []; + while ($machine = $machinedb->fetch(PDO::FETCH_ASSOC)) { + settype($machine['locationid'], 'int'); + $machines[] = $machine; + } + // Options not yet used. + $options = json_decode($row['options']); + if ($row['action'] === 'sd') RebootControl::execute($machines, RebootControl::SHUTDOWN, 0); + else if ($row['action'] === 'wol') RebootControl::wakeMachines($machines); +} + /* * Client reachability test -- can be disabled */ -- cgit v1.2.3-55-g7522