summaryrefslogtreecommitdiffstats
path: root/modules-available/remoteaccess
diff options
context:
space:
mode:
authorSimon Rettberg2020-06-29 14:04:45 +0200
committerSimon Rettberg2020-06-29 14:04:45 +0200
commit476e31372ae49736dad1df387b657f8a683f767b (patch)
tree17625f8e58050dac0d1df5035efc273d6bdcec99 /modules-available/remoteaccess
parent[statistics_reporting] Fix numer of unique users and server CPU model (diff)
downloadslx-admin-476e31372ae49736dad1df387b657f8a683f767b.tar.gz
slx-admin-476e31372ae49736dad1df387b657f8a683f767b.tar.xz
slx-admin-476e31372ae49736dad1df387b657f8a683f767b.zip
[remoteaccess] Fix/Improve WOL behavior
Enable rebootcontrol module in ensureMachinesRunning(), so it works from the call in api.inc.php. Consider machines that we sent a WOL packet to during the last 90 seconds as online when counting number of idle machines, so slow booting machines won't cause us to wake too many machines.
Diffstat (limited to 'modules-available/remoteaccess')
-rw-r--r--modules-available/remoteaccess/hooks/cron.inc.php3
-rw-r--r--modules-available/remoteaccess/inc/remoteaccess.inc.php17
2 files changed, 12 insertions, 8 deletions
diff --git a/modules-available/remoteaccess/hooks/cron.inc.php b/modules-available/remoteaccess/hooks/cron.inc.php
index 3e0e130b..2ee6e375 100644
--- a/modules-available/remoteaccess/hooks/cron.inc.php
+++ b/modules-available/remoteaccess/hooks/cron.inc.php
@@ -1,6 +1,3 @@
<?php
-if (!Module::isAvailable('rebootcontrol'))
- return;
-
RemoteAccess::ensureMachinesRunning();
diff --git a/modules-available/remoteaccess/inc/remoteaccess.inc.php b/modules-available/remoteaccess/inc/remoteaccess.inc.php
index fc719b37..37d33d45 100644
--- a/modules-available/remoteaccess/inc/remoteaccess.inc.php
+++ b/modules-available/remoteaccess/inc/remoteaccess.inc.php
@@ -19,11 +19,18 @@ class RemoteAccess
public static function ensureMachinesRunning()
{
- $res = Database::simpleQuery("SELECT rg.groupid, rg.wolcount, GROUP_CONCAT(rxl.locationid) AS locs FROM remoteaccess_group rg
- INNER JOIN remoteaccess_x_location rxl USING (groupid)
- WHERE rg.active = 1
- GROUP BY groupid");
+ if (!Module::isAvailable('rebootcontrol')) {
+ error_log("Not waking remote access machines: rebootcontrol missing");
+ return;
+ }
+
+ $res = Database::simpleQuery("SELECT rg.groupid, rg.groupname, rg.wolcount, GROUP_CONCAT(rxl.locationid) AS locs FROM remoteaccess_group rg
+ INNER JOIN remoteaccess_x_location rxl USING (groupid)
+ WHERE rg.active = 1
+ GROUP BY groupid");
+ // Consider machines we tried to wake in the past 90 seconds as online
+ $wolDeadline = time() - 90;
while ($row = $res->fetch(PDO::FETCH_ASSOC)) {
if ($row['wolcount'] <= 0)
continue;
@@ -33,7 +40,7 @@ class RemoteAccess
continue;
$active = Database::queryFirst("SELECT Count(*) AS cnt FROM machine m
INNER JOIN remoteaccess_machine rm USING (machineuuid)
- WHERE m.locationid IN ($locs) AND m.state = 'IDLE'");
+ WHERE m.locationid IN ($locs) AND (m.state = 'IDLE' OR rm.woltime > $wolDeadline)");
$active = (isset($active['cnt']) ? $active['cnt'] : 0);
$wantNum = $row['wolcount'] - $active;
if ($wantNum <= 0)