This commit is contained in:
2023-04-19 13:15:21 +08:00
parent c739912494
commit 3b0d556700
5 changed files with 30 additions and 19 deletions
+20 -10
View File
@@ -49,10 +49,10 @@ class HotReload extends Command
*/
protected function execute(InputInterface $input, OutputInterface $output)
{
$this->startProcess();
pcntl_signal(SIGINT | SIGQUIT | SIGTERM, function () {
Process::wait();
$this->stopProcess();
});
$this->startProcess();
if (extension_loaded('inotify')) {
$this->onInotifyReload();
} else {
@@ -70,6 +70,23 @@ class HotReload extends Command
$this->process = proc_open([PHP_BINARY, APP_PATH . 'kiri.php', 'sw:server', 'start'], [], $pipes);
}
/**
* @return void
* @throws Exception
*/
private function stopProcess(): void
{
if (!is_resource($this->process)) {
return;
}
$pid = (int)file_get_contents(storage('.swoole.pid'));
if (posix_kill($pid, 0)) {
posix_kill($pid, SIGTERM);
}
proc_close($this->process);
$this->process = null;
}
/**
* @return void
@@ -268,14 +285,7 @@ class HotReload extends Command
public function trigger_reload(): void
{
echo 'tigger server Reload' . PHP_EOL;
if (is_resource($this->process)) {
$pid = (int)file_get_contents(storage('.swoole.pid'));
if (posix_kill($pid, 0)) {
posix_kill($pid, SIGTERM);
}
proc_close($this->process);
}
$this->process = null;
$this->stopProcess();
$this->startProcess();
}