eee
This commit is contained in:
@@ -245,15 +245,38 @@ class FileWatcher extends AbstractProcess implements OnProcessInterface
|
||||
di(HotReloadState::class)->store($changedFiles);
|
||||
di(StdoutLogger::class)->println('detected file changes, reloading server: ' . $preview);
|
||||
|
||||
$server = di(ServerInterface::class);
|
||||
if (method_exists($server, 'reload')) {
|
||||
$server->reload();
|
||||
if (!$this->reloadWorkers()) {
|
||||
di(StdoutLogger::class)->println('reload server failed: master pid not found or signal failed');
|
||||
}
|
||||
} finally {
|
||||
$this->reloading = false;
|
||||
}
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
private function startInotify(): void
|
||||
{
|
||||
$this->inotifyFd = inotify_init();
|
||||
|
||||
Reference in New Issue
Block a user