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 { } else {
$driver = Kiri::getDi()->get(Inotify::class, [$this->dirs, $this]); $driver = Kiri::getDi()->get(Inotify::class, [$this->dirs, $this]);
} }
if (Kiri::getPlatform()->isLinux()) { if (Kiri::getPlatform()->isLinux()) {
swoole_set_process_name('[' . Config::get('id', 'sw service.') . '].sw:wather'); swoole_set_process_name('[' . Config::get('id', 'sw service.') . '].sw:wather');
} }
$this->trigger_reload(); $this->trigger_reload();
Coroutine::create(fn() => $this->onExit());
Coroutine::create(function () use ($driver) { Coroutine::create(function () use ($driver) {
$driver->start(); $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 * @throws Exception
*/ */