Passed
Push — master ( 721982...e05dd3 )
by Nils
03:23
created

ContainerIsRunningCheck::getIdentifier()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 0
dl 0
loc 3
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace Leankoala\HealthFoundation\Check\Docker\Container;
4
5
6
use Leankoala\HealthFoundation\Check\Check;
7
use Leankoala\HealthFoundation\Check\Result;
8
9
class ContainerIsRunningCheck implements Check
10
{
11
    const IDENTIFIER = 'base:docker:container:running';
12
13
    private $containerName;
14
15
    public function init($containerName)
16
    {
17
        $this->containerName = $containerName;
18
    }
19
20
    public function run()
21
    {
22
        $command = "docker inspect -f '{{.State.Running}}' " . $this->containerName . " 2>/dev/null ";
23
24
        exec($command, $output, $returnValue);
25
26
        $isRunning = ((bool)$output[0]);
27
28
        if ($isRunning) {
29
            return new Result(Result::STATUS_PASS, 'The container ' . $this->containerName . ' is running.');
30
        } else {
31
            return new Result(Result::STATUS_FAIL, 'The container ' . $this->containerName . ' is not running.');
32
        }
33
    }
34
35
    public function getIdentifier()
36
    {
37
        return self::IDENTIFIER . '.' . $this->containerName;
38
    }
39
}
40