summaryrefslogtreecommitdiffstats
path: root/inc/trigger.inc.php
diff options
context:
space:
mode:
Diffstat (limited to 'inc/trigger.inc.php')
-rw-r--r--inc/trigger.inc.php56
1 files changed, 26 insertions, 30 deletions
diff --git a/inc/trigger.inc.php b/inc/trigger.inc.php
index 5024b907..d0d5d365 100644
--- a/inc/trigger.inc.php
+++ b/inc/trigger.inc.php
@@ -1,5 +1,7 @@
<?php
+declare(strict_types=1);
+
/**
* This is one giant class containing various functions that will generate
* required config files, daemon instances and more, mostly through the Taskmanager.
@@ -14,20 +16,21 @@ class Trigger
/**
* Compile iPXE pxelinux menu. Needs to be done whenever the server's IP
* address changes.
- *
- * @param boolean $force force recompilation even if it seems up to date
- * @return boolean|string false if launching task failed, task-id otherwise
+ *
+ * @return ?string null if launching task failed, task-id otherwise
*/
- public static function ipxe()
+ public static function ipxe(string $taskId = null): ?string
{
+ static $lastResult = null;
+ if ($lastResult !== null)
+ return $lastResult;
$hooks = Hook::load('ipxe-update');
- static $taskId = false;
foreach ($hooks as $hook) {
$ret = function($taskId) use ($hook) {
$ret = include_once($hook->file);
if (is_string($ret))
return $ret;
- return isset($taskId) ? $taskId : false;
+ return $taskId;
};
$ret = $ret($taskId);
if (is_string($ret)) {
@@ -36,7 +39,7 @@ class Trigger
$taskId = $ret['id'];
}
}
- Property::set('ipxe-task-id', $taskId, 15);
+ $lastResult = $taskId;
return $taskId;
}
@@ -48,7 +51,7 @@ class Trigger
* @return boolean true if current configured IP address is still valid, or if a new address could
* successfully be determined, false otherwise
*/
- public static function autoUpdateServerIp()
+ public static function autoUpdateServerIp(): bool
{
for ($i = 0; $i < 5; ++$i) {
$task = Taskmanager::submit('LocalAddressesList');
@@ -59,7 +62,7 @@ class Trigger
if ($task === false)
return false;
$task = Taskmanager::waitComplete($task, 10000);
- if (!isset($task['data']['addresses']) || empty($task['data']['addresses']))
+ if (empty($task['data']['addresses']))
return false;
$serverIp = Property::getServerIp();
@@ -96,22 +99,18 @@ class Trigger
/**
* Mount the VM store into the server.
*
- * @param array $vmstore VM Store configuration to use. If false, read from properties
+ * @param array|false $vmstore VM Store configuration to use. If false, read from properties
* @param bool $ifLocalOnly Only execute task if the storage type is local (used for DNBD3)
- * @return string|false task id of mount procedure, or false on error
+ * @return ?string task id of mount procedure, or false on error
*/
- public static function mount($vmstore = false, $ifLocalOnly = false)
+ public static function mount($vmstore = false, bool $ifLocalOnly = false): ?string
{
if ($vmstore === false) {
$vmstore = Property::getVmStoreConfig();
}
if (!is_array($vmstore))
- return false;
- if (isset($vmstore['storetype'])) {
- $storetype = $vmstore['storetype'];
- } else {
- $storetype = 'unknown';
- }
+ return null;
+ $storetype = $vmstore['storetype'] ?? 'unknown';
if ($storetype === 'nfs') {
$addr = $vmstore['nfsaddr'];
$opts = 'nfsopts';
@@ -124,12 +123,8 @@ class Trigger
}
// Bail out if storage is not local, and we only want to run it in that case
if ($ifLocalOnly && $addr !== 'null')
- return false;
- if (isset($vmstore[$opts])) {
- $opts = $vmstore[$opts];
- }else {
- $opts = null;
- }
+ return null;
+ $opts = $vmstore[$opts] ?? null;
$status = Taskmanager::submit('MountVmStore', array(
'address' => $addr,
'type' => 'images',
@@ -143,7 +138,7 @@ class Trigger
// for the taskmanager to give us the existing id
$status = Taskmanager::waitComplete($status, 100);
}
- return $status['data']['existingTask'] ?? $status['id'] ?? false;
+ return $status['data']['existingTask'] ?? $status['id'] ?? null;
}
/**
@@ -151,7 +146,7 @@ class Trigger
*
* @return boolean Whether there are still callbacks pending
*/
- public static function checkCallbacks()
+ public static function checkCallbacks(): bool
{
$tasksLeft = false;
$callbackList = TaskmanagerCallback::getPendingCallbacks();
@@ -162,15 +157,16 @@ class Trigger
foreach ($callbacks as $callback) {
TaskmanagerCallback::handleCallback($callback, $status);
}
- if (Taskmanager::isFailed($status) || Taskmanager::isFinished($status))
+ if (Taskmanager::isFailed($status) || Taskmanager::isFinished($status)) {
Taskmanager::release($status);
- else
+ } else {
$tasksLeft = true;
+ }
}
return $tasksLeft;
}
- private static function triggerDaemons($action, $parent, &$taskids)
+ private static function triggerDaemons(string $action, ?string $parent, array &$taskids): ?string
{
$task = Taskmanager::submit('Systemctl', array(
'operation' => $action,
@@ -198,7 +194,7 @@ class Trigger
/**
* Stop any daemons that might be sitting on the VMstore, or database.
*/
- public static function stopDaemons($parent, &$taskids)
+ public static function stopDaemons(?string $parent, array &$taskids): ?string
{
$parent = self::triggerDaemons('stop', $parent, $taskids);
$task = Taskmanager::submit('LdadpLauncher', array(