This commit is contained in:
2021-11-30 18:23:56 +08:00
parent 4107b5bb07
commit 9f3355cab4
+18 -3
View File
@@ -2,14 +2,15 @@
namespace Kiri\FileListen; namespace Kiri\FileListen;
use Note\Inject;
use Exception; use Exception;
use Kiri\Abstracts\Config; use Kiri\Abstracts\Config;
use Kiri\Error\Logger; use Kiri\Error\Logger;
use Kiri\Exception\ConfigException; use Kiri\Exception\ConfigException;
use Kiri\Kiri; use Kiri\Kiri;
use Note\Inject;
use Swoole\Coroutine; use Swoole\Coroutine;
use Swoole\Process; use Swoole\Process;
use Swoole\Timer;
use Symfony\Component\Console\Command\Command; use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface; use Symfony\Component\Console\Output\OutputInterface;
@@ -81,7 +82,8 @@ class HotReload extends Command
} }
$this->trigger_reload(); $this->trigger_reload();
var_dump(getmypid()); Timer::tick(1000, fn() => $this->healthCheck());
Process::signal(SIGTERM, [$this, 'onSignal']); Process::signal(SIGTERM, [$this, 'onSignal']);
Process::signal(SIGKILL, [$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 * @param $data
* @throws Exception * @throws Exception
@@ -138,7 +153,7 @@ class HotReload extends Command
public function trigger_reload() public function trigger_reload()
{ {
$this->logger->warning('change reload'); $this->logger->warning('change reload');
$pid = $this->process?->pid; $pid = $this->process?->pid;
$process = new Process(function (Process $process) { $process = new Process(function (Process $process) {
$process->exec(PHP_BINARY, [APP_PATH . "kiri.php", "sw:server", "restart"]); $process->exec(PHP_BINARY, [APP_PATH . "kiri.php", "sw:server", "restart"]);
}); });