Compare commits
8 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| b4ac5c4758 | |||
| d161477957 | |||
| a26b99dd1e | |||
| 86e4a92ab0 | |||
| ea425bb82d | |||
| ad0154d319 | |||
| edb70d2b9b | |||
| 9f3355cab4 |
@@ -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,22 @@ class HotReload extends Command
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @throws Exception
|
||||
*/
|
||||
public function healthCheck()
|
||||
{
|
||||
$pid = (int)file_get_contents(storage('.swoole.pid'));
|
||||
if (empty($pid)) {
|
||||
$this->logger->warning('service is shutdown you need reload.');
|
||||
$this->trigger_reload();
|
||||
} else if (!Process::kill($pid, 0)) {
|
||||
$this->logger->warning('service is shutdown you need reload.');
|
||||
$this->trigger_reload();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param $data
|
||||
* @throws Exception
|
||||
@@ -138,9 +156,11 @@ 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"]);
|
||||
|
||||
$this->logger->warning('service stop.');
|
||||
});
|
||||
$process->start();
|
||||
if ($pid && Process::kill($pid, 0)) {
|
||||
|
||||
Reference in New Issue
Block a user