summaryrefslogtreecommitdiffstats
path: root/library/Director/Web/Widget/Daemon/BackgroundDaemonState.php
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--library/Director/Web/Widget/Daemon/BackgroundDaemonState.php57
1 files changed, 57 insertions, 0 deletions
diff --git a/library/Director/Web/Widget/Daemon/BackgroundDaemonState.php b/library/Director/Web/Widget/Daemon/BackgroundDaemonState.php
new file mode 100644
index 0000000..03e76b2
--- /dev/null
+++ b/library/Director/Web/Widget/Daemon/BackgroundDaemonState.php
@@ -0,0 +1,57 @@
+<?php
+
+namespace Icinga\Module\Director\Web\Widget\Daemon;
+
+use Icinga\Module\Director\Daemon\RunningDaemonInfo;
+use Icinga\Module\Director\Db;
+
+class BackgroundDaemonState
+{
+ protected $db;
+
+ /** @var RunningDaemonInfo[] */
+ protected $instances;
+
+ public function __construct(Db $db)
+ {
+ $this->db = $db;
+ }
+
+ public function isRunning()
+ {
+ foreach ($this->getInstances() as $instance) {
+ if ($instance->isRunning()) {
+ return true;
+ }
+ }
+
+ return false;
+ }
+
+ protected function getInstances()
+ {
+ if ($this->instances === null) {
+ $this->instances = $this->fetchInfo();
+ }
+
+ return $this->instances;
+ }
+
+ /**
+ * @return RunningDaemonInfo[]
+ */
+ protected function fetchInfo()
+ {
+ $db = $this->db->getDbAdapter();
+ $daemons = $db->fetchAll(
+ $db->select()->from('director_daemon_info')->order('fqdn')->order('username')->order('pid')
+ );
+
+ $result = [];
+ foreach ($daemons as $info) {
+ $result[] = new RunningDaemonInfo($info);
+ }
+
+ return $result;
+ }
+}