|
1
|
|
|
<?php |
|
2
|
|
|
/* |
|
3
|
|
|
* MikoPBX - free phone system for small business |
|
4
|
|
|
* Copyright (C) 2017-2020 Alexey Portnov and Nikolay Beketov |
|
5
|
|
|
* |
|
6
|
|
|
* This program is free software: you can redistribute it and/or modify |
|
7
|
|
|
* it under the terms of the GNU General Public License as published by |
|
8
|
|
|
* the Free Software Foundation; either version 3 of the License, or |
|
9
|
|
|
* (at your option) any later version. |
|
10
|
|
|
* |
|
11
|
|
|
* This program is distributed in the hope that it will be useful, |
|
12
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
13
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
14
|
|
|
* GNU General Public License for more details. |
|
15
|
|
|
* |
|
16
|
|
|
* You should have received a copy of the GNU General Public License along with this program. |
|
17
|
|
|
* If not, see <https://www.gnu.org/licenses/>. |
|
18
|
|
|
*/ |
|
19
|
|
|
|
|
20
|
|
|
namespace MikoPBX\Core\System\Configs; |
|
21
|
|
|
|
|
22
|
|
|
use MikoPBX\Core\System\Util; |
|
23
|
|
|
use MikoPBX\Core\System\Processes; |
|
24
|
|
|
use Phalcon\Di\Injectable; |
|
25
|
|
|
|
|
26
|
|
|
class RedisConf extends Injectable |
|
27
|
|
|
{ |
|
28
|
|
|
public const PROC_NAME = 'redis-server'; |
|
29
|
|
|
public const CONF_FILE = '/etc/redis.conf'; |
|
30
|
|
|
|
|
31
|
|
|
/** |
|
32
|
|
|
* Restarts Beanstalk server |
|
33
|
|
|
*/ |
|
34
|
|
|
public function reStart(): void |
|
35
|
|
|
{ |
|
36
|
|
|
$this->configure(); |
|
37
|
|
|
$safeLink = "/usr/sbin/safe-" . self::PROC_NAME; |
|
38
|
|
|
Util::createUpdateSymlink('/etc/rc/worker_reload', $safeLink); |
|
39
|
|
|
Processes::killByName("safe-" . self::PROC_NAME); |
|
40
|
|
|
Processes::killByName(self::PROC_NAME); |
|
41
|
|
|
Processes::mwExecBg("{$safeLink} ".self::CONF_FILE); |
|
42
|
|
|
while (true) { |
|
43
|
|
|
$pid = Processes::getPidOfProcess(self::PROC_NAME); |
|
44
|
|
|
if (empty($pid)) { |
|
45
|
|
|
Util::echoWithSyslog(' - Wait for start ' . self::PROC_NAME . ' deamon ...' . PHP_EOL); |
|
46
|
|
|
sleep(2); |
|
47
|
|
|
} else { |
|
48
|
|
|
break; |
|
49
|
|
|
} |
|
50
|
|
|
} |
|
51
|
|
|
} |
|
52
|
|
|
|
|
53
|
|
|
/** |
|
54
|
|
|
* Setup ntp daemon conf file |
|
55
|
|
|
*/ |
|
56
|
|
|
private function configure(): void |
|
57
|
|
|
{ |
|
58
|
|
|
$config = $this->getDI()->get('config')->redis; |
|
59
|
|
|
$conf = "bind {$config->host}".PHP_EOL; |
|
60
|
|
|
$conf.= "port {$config->port}".PHP_EOL; |
|
61
|
|
|
Util::fileWriteContent(self::CONF_FILE, $conf); |
|
62
|
|
|
} |
|
63
|
|
|
} |