1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Hhxsv5\LaravelS\Illuminate; |
4
|
|
|
|
5
|
|
|
use Illuminate\Console\Command; |
|
|
|
|
6
|
|
|
use Illuminate\Filesystem\Filesystem; |
|
|
|
|
7
|
|
|
|
8
|
|
|
class LaravelSCommand extends Command |
9
|
|
|
{ |
10
|
|
|
protected $signature = 'laravels {action?}'; |
11
|
|
|
|
12
|
|
|
protected $description = 'LaravelS Console Tool'; |
13
|
|
|
|
14
|
|
|
protected $actions; |
15
|
|
|
|
16
|
|
|
protected $isLumen = false; |
17
|
|
|
|
18
|
|
|
protected $files; |
19
|
|
|
|
20
|
|
|
public function __construct(Filesystem $files) |
21
|
|
|
{ |
22
|
|
|
parent::__construct(); |
23
|
|
|
|
24
|
|
|
$this->actions = ['start', 'stop', 'restart', 'reload', 'publish']; |
25
|
|
|
$this->description .= ': ' . implode('|', $this->actions); |
26
|
|
|
$this->files = $files; |
27
|
|
|
} |
28
|
|
|
|
29
|
|
|
public function fire() |
30
|
|
|
{ |
31
|
|
|
$this->handle(); |
32
|
|
|
} |
33
|
|
|
|
34
|
|
|
public function handle() |
35
|
|
|
{ |
36
|
|
|
$action = $this->argument('action'); |
37
|
|
|
if (!in_array($action, $this->actions, true)) { |
38
|
|
|
$this->info('php laravels {' . implode('|', $this->actions) . '}'); |
39
|
|
|
return; |
40
|
|
|
} |
41
|
|
|
$this->info('LaravelS for ' . $this->getApplication()->getLongVersion()); |
42
|
|
|
$this->isLumen = stripos($this->getApplication()->getVersion(), 'Lumen') !== false; |
43
|
|
|
$this->{$action}(); |
44
|
|
|
} |
45
|
|
|
|
46
|
|
|
protected function start() |
47
|
|
|
{ |
48
|
|
|
$laravelConf = ['rootPath' => base_path(), 'isLumen' => $this->isLumen]; |
|
|
|
|
49
|
|
|
$svrConf = config('laravels'); |
|
|
|
|
50
|
|
|
if (file_exists($svrConf['swoole']['pid_file'])) { |
51
|
|
|
$pid = file_get_contents($svrConf['swoole']['pid_file']); |
52
|
|
|
if (posix_kill($pid, 0)) { |
|
|
|
|
53
|
|
|
$this->warn("LaravelS: PID[{$pid}] is already running."); |
54
|
|
|
return; |
55
|
|
|
} |
56
|
|
|
} |
57
|
|
|
|
58
|
|
|
// Implements gracefully reload, avoid including laravel's files before worker start |
59
|
|
|
$cmd = sprintf('%s %s/../GoLaravelS.php', PHP_BINARY, __DIR__); |
60
|
|
|
$fp = popen($cmd, 'w'); |
61
|
|
|
fwrite($fp, json_encode(compact('svrConf', 'laravelConf'))); |
|
|
|
|
62
|
|
|
fclose($fp); |
|
|
|
|
63
|
|
|
$pidFile = config('laravels.swoole.pid_file'); |
64
|
|
|
$this->info(sprintf('LaravelS: PID[%s] is running.', file_get_contents($pidFile))); |
65
|
|
|
} |
66
|
|
|
|
67
|
|
|
protected function stop($ignoreErr = false) |
68
|
|
|
{ |
69
|
|
|
$pidFile = config('laravels.swoole.pid_file'); |
|
|
|
|
70
|
|
|
if (file_exists($pidFile)) { |
71
|
|
|
$pid = file_get_contents($pidFile); |
72
|
|
|
if (posix_kill($pid, 0)) { |
|
|
|
|
73
|
|
|
if (posix_kill($pid, SIGTERM)) { |
74
|
|
|
// Make sure that master process quit |
75
|
|
|
$time = 0; |
76
|
|
|
while (posix_getpgid($pid) && $time <= 20) { |
|
|
|
|
77
|
|
|
usleep(100000); |
78
|
|
|
$time++; |
79
|
|
|
} |
80
|
|
|
$this->info("LaravelS: PID[{$pid}] is stopped."); |
81
|
|
|
} else { |
82
|
|
|
$this->error("LaravelS: PID[{$pid}] is stopped failed."); |
83
|
|
|
} |
84
|
|
|
} else { |
85
|
|
|
$this->warn("LaravelS: PID[{$pid}] does not exist, or permission denied."); |
86
|
|
|
if (!$ignoreErr) { |
87
|
|
|
return; |
88
|
|
|
} |
89
|
|
|
} |
90
|
|
|
} else { |
91
|
|
|
$this->info('LaravelS: already stopped.'); |
92
|
|
|
} |
93
|
|
|
} |
94
|
|
|
|
95
|
|
|
protected function restart() |
96
|
|
|
{ |
97
|
|
|
$this->stop(true); |
98
|
|
|
$this->start(); |
99
|
|
|
} |
100
|
|
|
|
101
|
|
|
protected function reload() |
102
|
|
|
{ |
103
|
|
|
$pidFile = config('laravels.swoole.pid_file'); |
|
|
|
|
104
|
|
|
if (!file_exists($pidFile)) { |
105
|
|
|
$this->error('LaravelS: it seems that LaravelS is not running.'); |
106
|
|
|
return; |
107
|
|
|
} |
108
|
|
|
|
109
|
|
|
$pid = file_get_contents($pidFile); |
110
|
|
|
if (!posix_kill($pid, 0)) { |
|
|
|
|
111
|
|
|
$this->error("LaravelS: PID[{$pid}] does not exist, or permission denied."); |
112
|
|
|
return; |
113
|
|
|
} |
114
|
|
|
|
115
|
|
|
if (posix_kill($pid, SIGUSR1)) { |
116
|
|
|
$this->info("LaravelS: PID[{$pid}] is reloaded."); |
117
|
|
|
} else { |
118
|
|
|
$this->error("LaravelS: PID[{$pid}] is reloaded failed."); |
119
|
|
|
} |
120
|
|
|
} |
121
|
|
|
|
122
|
|
|
protected function publish() |
123
|
|
|
{ |
124
|
|
|
$to = base_path('config/laravels.php'); |
|
|
|
|
125
|
|
|
if (file_exists($to)) { |
126
|
|
|
$choice = $this->anticipate($to . ' already exists, do you want to override it ? Y/N', ['Y', 'N'], 'N'); |
127
|
|
|
if (!$choice || strtoupper($choice) === 'N') { |
128
|
|
|
$this->info('Publishing complete.'); |
129
|
|
|
return; |
130
|
|
|
} |
131
|
|
|
} |
132
|
|
|
|
133
|
|
|
try { |
134
|
|
|
$this->call('vendor:publish', ['--provider' => LaravelSServiceProvider::class, '--force' => true]); |
135
|
|
|
return; |
136
|
|
|
} catch (\Exception $e) { |
137
|
|
|
if (!($e instanceof \InvalidArgumentException)) { |
138
|
|
|
throw $e; |
139
|
|
|
} |
140
|
|
|
} |
141
|
|
|
$from = __DIR__ . '/../Config/laravels.php'; |
142
|
|
|
|
143
|
|
|
$toDir = dirname($to); |
144
|
|
|
|
145
|
|
|
if (!$this->files->isDirectory($toDir)) { |
146
|
|
|
$this->files->makeDirectory($toDir, 0755, true); |
147
|
|
|
} |
148
|
|
|
|
149
|
|
|
$this->files->copy($from, $to); |
150
|
|
|
|
151
|
|
|
$from = str_replace(base_path(), '', realpath($from)); |
152
|
|
|
|
153
|
|
|
$to = str_replace(base_path(), '', realpath($to)); |
154
|
|
|
|
155
|
|
|
$this->line('<info>Copied File</info> <comment>[' . $from . ']</comment> <info>To</info> <comment>[' . $to . ']</comment>'); |
156
|
|
|
} |
157
|
|
|
|
158
|
|
|
public function getDescription() |
159
|
|
|
{ |
160
|
|
|
return $this->description; |
161
|
|
|
} |
162
|
|
|
} |
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"]
, you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths