diff --git a/kiri-engine/FileListen/HotReload.php b/kiri-engine/FileListen/HotReload.php index 29cb186f..68d78d6e 100644 --- a/kiri-engine/FileListen/HotReload.php +++ b/kiri-engine/FileListen/HotReload.php @@ -63,11 +63,11 @@ class HotReload extends Command } else { $driver = Kiri::getDi()->get(Inotify::class, [$this->dirs, $this]); } - if (Kiri::getPlatform()->isLinux()) { swoole_set_process_name('[' . Config::get('id', 'sw service.') . '].sw:wather'); } $this->trigger_reload(); + Coroutine::create(fn() => $this->onExit()); Coroutine::create(function () use ($driver) { $driver->start(); }); @@ -75,6 +75,23 @@ class HotReload extends Command } + /** + * @throws Exception + */ + public function onExit() + { + $data = Coroutine::waitSignal(SIGTERM | SIGKILL, -1); + if ($data) { + $pid = file_get_contents(storage('.swoole.pid')); + if (!empty($pid) && Process::kill($pid, 0)) { + Process::kill($pid, SIGTERM); + } + $this->stop(); + $this->source = null; + } + } + + /** * @throws Exception */