This commit is contained in:
2026-07-08 09:42:56 +08:00
parent 0adfe14a1f
commit 7f36bb0d53
5 changed files with 78 additions and 12 deletions
+27 -2
View File
@@ -7,7 +7,6 @@ use Kiri\Error\StdoutLogger;
use Kiri\Events\EventProvider;
use Kiri\Router\Router;
use Kiri\Server\Events\OnWorkerStart;
use Kiri\Server\ServerInterface;
use Psr\Log\LoggerInterface;
use Swoole\Event;
use Swoole\Process;
@@ -116,7 +115,9 @@ class HotReload extends AbstractProcess
di(StdoutLogger::class)->println('reloading server[' . \config('site.id', 'system-service') . '], please waite.');
$this->clear();
di(ServerInterface::class)->reload();
if (!$this->reloadWorkers()) {
di(StdoutLogger::class)->println('reload server failed: master pid not found or signal failed');
}
$this->addListen();
$this->reloading = false;
@@ -126,6 +127,30 @@ class HotReload extends AbstractProcess
/**
* @return void
*/
private function reloadWorkers(): bool
{
$pid = $this->getMasterPid();
if ($pid === null) {
return false;
}
return Process::kill($pid, SIGUSR1);
}
private function getMasterPid(): ?int
{
$pidFile = function_exists('storage') ? storage('.swoole.pid') : '';
if (!is_file($pidFile)) {
return null;
}
$pid = (int)trim((string)file_get_contents($pidFile));
if ($pid <= 1 || !Process::kill($pid, 0)) {
return null;
}
return $pid;
}
protected function addListen(): void
{
foreach (config('servers.reload.listen') as $value) {