summaryrefslogtreecommitdiffstats
path: root/library/Director/Daemon/RunningDaemonInfo.php
blob: adb3549d20a4a3b0ac3a875ce8c1d7d3d22c7fbb (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
<?php

namespace Icinga\Module\Director\Daemon;

class RunningDaemonInfo
{
    /** @var object */
    protected $info;

    public function __construct($info = null)
    {
        $this->setInfo($info);
    }

    public function setInfo($info)
    {
        if (empty($info)) {
            $this->info = $this->createEmptyInfo();
        } else {
            $this->info = $info;
        }

        return $this;
    }

    public function isRunning()
    {
        return $this->getPid() !== null && ! $this->isOutdated();
    }

    public function getPid()
    {
        return (int) $this->info->pid;
    }

    public function getUsername()
    {
        return $this->info->username;
    }

    public function getFqdn()
    {
        return $this->info->fqdn;
    }

    public function getLastUpdate()
    {
        return $this->info->ts_last_update;
    }

    public function getLastModification()
    {
        return $this->info->ts_last_modification;
    }

    public function getPhpVersion()
    {
        return $this->info->php_version;
    }

    public function hasBeenStopped()
    {
        return $this->getTimestampStopped() !== null;
    }

    public function getTimestampStarted()
    {
        return $this->info->ts_started;
    }

    public function getTimestampStopped()
    {
        return $this->info->ts_stopped;
    }

    public function isOutdated($seconds = 5)
    {
        return (
            DaemonUtil::timestampWithMilliseconds() - $this->info->ts_last_update
        ) > $seconds * 1000;
    }

    public function isRunningWithSystemd()
    {
        return $this->info->running_with_systemd === 'y';
    }

    public function getBinaryPath()
    {
        return $this->info->binary_path;
    }

    public function getBinaryRealpath()
    {
        return $this->info->binary_realpath;
    }

    public function binaryRealpathDiffers()
    {
        return $this->getBinaryPath() !== $this->getBinaryRealpath();
    }

    public function getPhpBinaryPath()
    {
        return $this->info->php_binary_path;
    }

    public function getPhpBinaryRealpath()
    {
        return $this->info->php_binary_realpath;
    }

    public function phpBinaryRealpathDiffers()
    {
        return $this->getPhpBinaryPath() !== $this->getPhpBinaryRealpath();
    }

    public function getPhpIntegerSize()
    {
        return (int) $this->info->php_integer_size;
    }

    public function has64bitIntegers()
    {
        return $this->getPhpIntegerSize() === 8;
    }

    /*
    // TODO: not yet
    public function isMaster()
    {
        return $this->info->is_master === 'y';
    }

    public function isStandby()
    {
        return ! $this->isMaster();
    }
    */

    protected function createEmptyInfo()
    {
        return (object) [
            'pid'                    => null,
            'fqdn'                   => null,
            'username'               => null,
            'php_version'            => null,
            // 'is_master'              => null,
            // Only if not running. Does this make any sense in 'empty info'?
            'ts_last_update'         => null,
            'ts_last_modification'   => null
        ];
    }
}