Compare commits

...

7 Commits

Author SHA1 Message Date
as2252258 a26b99dd1e 改名 2021-11-30 18:33:22 +08:00
as2252258 86e4a92ab0 改名 2021-11-30 18:31:41 +08:00
as2252258 ea425bb82d 改名 2021-11-30 18:30:15 +08:00
as2252258 ad0154d319 改名 2021-11-30 18:29:10 +08:00
as2252258 edb70d2b9b 改名 2021-11-30 18:26:23 +08:00
as2252258 9f3355cab4 改名 2021-11-30 18:23:56 +08:00
as2252258 4107b5bb07 改名 2021-11-30 15:48:18 +08:00
2 changed files with 27 additions and 4 deletions
+1 -1
View File
@@ -30,7 +30,7 @@
"swiftmailer/swiftmailer": "v6.3.*",
"psr/container": "^2.0",
"psr/http-server-middleware": "1.0.1",
"game-worker/kiri-event": "v1.0",
"game-worker/kiri-event": "^v1.0",
"ext-inotify": "*"
},
"autoload": {
+26 -3
View File
@@ -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,25 @@ class HotReload extends Command
}
/**
* @throws Exception
*/
public function healthCheck()
{
$pid = (int)file_get_contents(storage('.swoole.pid'));
$this->logger->debug('timer ticker.' . $pid . '.' . Process::kill($pid, 0));
if (empty($pid)) {
$this->trigger_reload();
} else if (!Process::kill($pid, 0)) {
if ($this->process && Process::kill($this->process->pid, 0)) {
echo 'service is shutdown you need reload.';
Process::kill($this->process->pid, -15);
}
$this->trigger_reload();
}
}
/**
* @param $data
* @throws Exception
@@ -138,9 +159,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)) {