summaryrefslogtreecommitdiffstats
path: root/inc/trigger.inc.php
diff options
context:
space:
mode:
authorSimon Rettberg2014-05-23 20:49:02 +0200
committerSimon Rettberg2014-05-23 20:49:02 +0200
commitfe6ac16498b05d0f0c8ed7fda394273815d3d6da (patch)
treecadf5f103ef3db7ba1b40d59d85937c998aad22f /inc/trigger.inc.php
parentServer Setup page (diff)
downloadslx-admin-fe6ac16498b05d0f0c8ed7fda394273815d3d6da.tar.gz
slx-admin-fe6ac16498b05d0f0c8ed7fda394273815d3d6da.tar.xz
slx-admin-fe6ac16498b05d0f0c8ed7fda394273815d3d6da.zip
Stuff (WIP)
Diffstat (limited to 'inc/trigger.inc.php')
-rw-r--r--inc/trigger.inc.php40
1 files changed, 40 insertions, 0 deletions
diff --git a/inc/trigger.inc.php b/inc/trigger.inc.php
new file mode 100644
index 00000000..40d9c491
--- /dev/null
+++ b/inc/trigger.inc.php
@@ -0,0 +1,40 @@
+<?php
+
+/**
+ * This is one giant class containing various functions that will generate
+ * required config files, daemon instances and more, mostly through the Taskmanager.
+ * Most function *should* only actually do something if it is required to do so.
+ * eg. a "launchSomething" function should only launch something if it isn't already
+ * running. Checking if something is running can happen in that very function, or in
+ * a task that the function is calling.
+ */
+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 true if already up to date, false if launching task failed, task-id otherwise
+ */
+ public static function ipxe($force = false)
+ {
+ if (!$force && Property::getIPxeIp() === Property::getServerIp())
+ return true; // Nothing to do
+ $last = Property::getIPxeTaskId();
+ if ($last !== false) {
+ $status = Taskmanager::status($last);
+ if (isset($status['statusCode']) && ($status['statusCode'] === TASK_WAITING || $status['statusCode'] === TASK_RUNNING))
+ return false; // Already compiling
+ }
+ $task = Taskmanager::submit('CompileIPxe', array(
+ 'ip' => Property::getServerIp()
+ ));
+ if (!isset($task['id']))
+ return false;
+ Property::setIPxeTaskId($task['id']);
+ return $task['id'];
+ }
+
+} \ No newline at end of file