-
-
Notifications
You must be signed in to change notification settings - Fork 51
Expand file tree
/
Copy pathStartCommand.php
More file actions
53 lines (46 loc) · 1.32 KB
/
StartCommand.php
File metadata and controls
53 lines (46 loc) · 1.32 KB
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
<?php
declare(strict_types=1);
/**
* This file is part of Simps.
*
* @link https://simps.io
* @document https://doc.simps.io
* @license https://github.com/simple-swoole/simps/blob/master/LICENSE
*/
namespace Simps\Console\Server;
use Simps\Application;
use Simps\Console\Command;
class StartCommand extends Command
{
protected $command = 'start';
protected $help = 'Start the specified service';
public function handle()
{
$ser = $this->params[0] ?? 'http';
$met = 'start';
// 检测服务是否已经启动
$pid = (int) @file_get_contents(sprintf($this->pid, $ser));
if ($pid > 0) {
$r = \Swoole\Process::kill($pid, 0);
if ($r) {
Application::echoError("Service `{$ser}` is running");
return;
}
}
// 获取服务配置并启动
$config = config('servers', []);
$config = $config[$ser] ?? null;
if (! $config) {
Application::echoError('Service does not exist');
exit;
}
$config['name'] = $ser;
$cls = $config['provider'];
$obj = new $cls($config);
if (method_exists($obj, $met)) {
$obj->{$met}();
} else {
Application::echoError('Service does not exist');
}
}
}