Passed
Push — develop ( b91c6d...602856 )
by Nikolay
05:44 queued 10s
created

SyslogConf   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 37
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 5
eloc 19
c 1
b 0
f 0
dl 0
loc 37
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A reStart() 0 21 4
A getSyslogFile() 0 5 1
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, 7 2020
7
 *
8
 */
9
10
namespace MikoPBX\Core\System\Configs;
11
12
13
use MikoPBX\Core\System\System;
14
use MikoPBX\Core\System\Util;
15
use Phalcon\Di\Injectable;
16
17
class SyslogConf extends Injectable
18
{
19
    /**
20
     * Restarts syslog daemon
21
     */
22
    public function reStart(): void
23
    {
24
        $syslog_file = '/var/log/messages';
25
        $log_file    = self::getSyslogFile();
26
        if ( ! file_exists($syslog_file)) {
27
            file_put_contents($syslog_file, '');
28
        }
29
        $syslogdPath = Util::which('syslogd');
30
        $busyboxPath = Util::which('busybox');
31
        $logreadPath = Util::which('logread');
32
        $killPath = Util::which('kill');
33
        $pid = Util::getPidOfProcess($syslogdPath);
34
        if ( ! empty($pid)) {
35
            $options = file_exists($log_file) ? '>' : '';
36
            Util::mwExec("{$busyboxPath} {$logreadPath} 2> /dev/null >" . $options . $log_file);
37
            // Завершаем процесс.
38
            Util::mwExec("{$busyboxPath} {$killPath} '$pid'");
39
        }
40
41
        Util::createUpdateSymlink($log_file, $syslog_file);
42
        Util::mwExec("{$syslogdPath} -O {$log_file} -b 10 -s 10240");
43
    }
44
45
    /**
46
     * Returns Syslog file path
47
     * @return string
48
     */
49
    public static function getSyslogFile(): string
50
    {
51
        $logdir = System::getLogDir() . '/system';
52
        Util::mwMkdir($logdir);
53
        return "$logdir/messages";
54
    }
55
}