This commit is contained in:
2021-11-19 03:24:09 +08:00
parent fa78d360b0
commit 5638d171d0
+7 -4
View File
@@ -9,6 +9,7 @@ use Kiri\Abstracts\Logger;
use Kiri\Exception\ConfigException; use Kiri\Exception\ConfigException;
use Kiri\Kiri; use Kiri\Kiri;
use Swoole\Coroutine; use Swoole\Coroutine;
use Swoole\Event;
use Swoole\Process; use Swoole\Process;
use Symfony\Component\Console\Command\Command; use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Input\InputInterface;
@@ -31,6 +32,8 @@ class HotReload extends Command
public int $int = -1; public int $int = -1;
private Scaner|Inotify $driver;
private ?Process $process = NULL; private ?Process $process = NULL;
@@ -65,9 +68,9 @@ class HotReload extends Command
$this->dirs = Config::get('inotify', [APP_PATH . 'app']); $this->dirs = Config::get('inotify', [APP_PATH . 'app']);
if (!extension_loaded('inotify')) { if (!extension_loaded('inotify')) {
$driver = Kiri::getDi()->get(Scaner::class, [$this->dirs, $this]); $this->driver = Kiri::getDi()->get(Scaner::class, [$this->dirs, $this]);
} else { } else {
$driver = Kiri::getDi()->get(Inotify::class, [$this->dirs, $this]); $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');
@@ -75,7 +78,7 @@ class HotReload extends Command
$this->trigger_reload(); $this->trigger_reload();
Process::signal(SIGKILL, [$this, 'onSignal']); Process::signal(SIGKILL, [$this, 'onSignal']);
Process::signal(SIGTERM, [$this, 'onSignal']); Process::signal(SIGTERM, [$this, 'onSignal']);
$driver->start(); $this->driver->start();
return 0; return 0;
} }
@@ -90,7 +93,7 @@ class HotReload extends Command
if (!empty($pid) && Process::kill($pid, 0)) { if (!empty($pid) && Process::kill($pid, 0)) {
Process::kill($pid, SIGTERM); Process::kill($pid, SIGTERM);
} }
exit(0); $this->driver->clear();
} }