This commit is contained in:
2021-11-18 17:50:05 +08:00
parent a290108ddd
commit 1fa7d3a3ba
+18 -1
View File
@@ -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
*/