From 9f3355cab4ba6793313a25eb6e3c160869a34215 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=90=91=E6=9E=97?= Date: Tue, 30 Nov 2021 18:23:56 +0800 Subject: [PATCH] =?UTF-8?q?=E6=94=B9=E5=90=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- kiri-engine/FileListen/HotReload.php | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/kiri-engine/FileListen/HotReload.php b/kiri-engine/FileListen/HotReload.php index 98675f3d..ff8dc4e2 100644 --- a/kiri-engine/FileListen/HotReload.php +++ b/kiri-engine/FileListen/HotReload.php @@ -2,14 +2,15 @@ namespace Kiri\FileListen; -use Note\Inject; use Exception; use Kiri\Abstracts\Config; use Kiri\Error\Logger; use Kiri\Exception\ConfigException; use Kiri\Kiri; +use Note\Inject; use Swoole\Coroutine; use Swoole\Process; +use Swoole\Timer; use Symfony\Component\Console\Command\Command; use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Output\OutputInterface; @@ -81,7 +82,8 @@ class HotReload extends Command } $this->trigger_reload(); - var_dump(getmypid()); + Timer::tick(1000, fn() => $this->healthCheck()); + Process::signal(SIGTERM, [$this, 'onSignal']); Process::signal(SIGKILL, [$this, 'onSignal']); @@ -90,6 +92,19 @@ class HotReload extends Command } + /** + * @throws Exception + */ + public function healthCheck() + { + if ($this->process && !Process::kill($this->process->pid, 0)) { + echo 'service is shutdown you need reload.'; + + $this->trigger_reload(); + } + } + + /** * @param $data * @throws Exception @@ -138,7 +153,7 @@ class HotReload extends Command public function trigger_reload() { $this->logger->warning('change reload'); - $pid = $this->process?->pid; + $pid = $this->process?->pid; $process = new Process(function (Process $process) { $process->exec(PHP_BINARY, [APP_PATH . "kiri.php", "sw:server", "restart"]); });