Passed
Pull Request — master (#23)
by Nikolay
09:42 queued 03:08
created

BeanstalkConf   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 25
Duplicated Lines 0 %

Importance

Changes 3
Bugs 0 Features 0
Metric Value
wmc 4
eloc 17
c 3
b 0
f 0
dl 0
loc 25
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
A reStart() 0 20 4
1
<?php
2
/*
3
 * Copyright (C) MIKO LLC - All Rights Reserved
4
 * Unauthorized copying of this file, via any medium is strictly prohibited
5
 * Proprietary and confidential
6
 * Written by Nikolay Beketov, 11 2020
7
 *
8
 */
9
10
namespace MikoPBX\Core\System\Configs;
11
12
13
use MikoPBX\Core\System\MikoPBXConfig;
14
use MikoPBX\Core\System\System;
15
use MikoPBX\Core\System\Util;
16
use MikoPBX\Core\System\Processes;
17
use Phalcon\Di;
18
use Phalcon\Di\Injectable;
19
20
class BeanstalkConf extends Injectable
21
{
22
    /**
23
     * Restarts Beanstalk server
24
     */
25
    public function reStart(): void
26
    {
27
        $config = $this->getDI()->get('config')->beanstalk;
28
29
        $beanstalkdPath = Util::which('beanstalkd');
30
        $conf = "-l {$config->host} -p {$config->port} -z 524280";
31
        if (Util::isSystemctl()) {
32
            $systemCtrlPath = Util::which('systemctl');
33
            Processes::mwExec("{$systemCtrlPath} restart beanstalkd.service");
34
        } else {
35
            Processes::killByName('beanstalkd');
36
            Processes::mwExecBg("{$beanstalkdPath} {$conf}");
37
        }
38
        while (true) {
39
            $pid = Processes::getPidOfProcess('beanstalkd');
40
            if (empty($pid)) {
41
                Util::echoWithSyslog(' - Wait for start beanstalkd deamon ...' . PHP_EOL);
42
                sleep(2);
43
            } else {
44
                break;
45
            }
46
        }
47
    }
48
}