Compare commits

...

7 Commits

Author SHA1 Message Date
as2252258 7e43775b04 改名 2021-11-19 18:27:17 +08:00
as2252258 dd4e9be06a 改名 2021-11-19 18:25:54 +08:00
as2252258 73b01c288b 改名 2021-11-19 18:23:06 +08:00
as2252258 f4f48ebad7 改名 2021-11-19 18:21:59 +08:00
as2252258 ef95f912cb 改名 2021-11-19 18:19:02 +08:00
as2252258 8bbb6adcc7 改名 2021-11-19 18:15:05 +08:00
as2252258 a855765365 改名 2021-11-19 18:13:48 +08:00
3 changed files with 21 additions and 18 deletions
+8 -9
View File
@@ -138,17 +138,16 @@ class HotReload extends Command
public function trigger_reload() public function trigger_reload()
{ {
$this->logger->warning('change reload'); $this->logger->warning('change reload');
// $pid = file_get_contents(storage('.swoole.pid')); $pid = $this->process?->pid;
// if (!empty($pid) && Process::kill($pid, 0)) { $process = new Process(function (Process $process) {
// Process::kill($pid, SIGTERM);
// }
if ($this->process && Process::kill($this->process->pid, 0)) {
Process::kill($this->process->pid) && Process::wait(true);
}
$this->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"]);
}); });
$this->process->start(); $process->start();
if ($pid && Process::kill($pid, 0)) {
Process::kill($pid) && Process::wait(true);
}
$this->process = null;
$this->process = $process;
} }
+6 -5
View File
@@ -61,11 +61,9 @@ class Inotify
return; return;
} }
if ($this->process->isReloading) { if ($this->process->isReloading) {
if (!$this->process->isReloadingOut) {
$this->process->isReloadingOut = true;
}
return; return;
} }
$LISTEN_TYPE = [IN_CREATE, IN_DELETE, IN_MODIFY, IN_MOVED_TO, IN_MOVED_FROM]; $LISTEN_TYPE = [IN_CREATE, IN_DELETE, IN_MODIFY, IN_MOVED_TO, IN_MOVED_FROM];
foreach ($events as $ev) { foreach ($events as $ev) {
if (!in_array($ev['mask'], $LISTEN_TYPE)) { if (!in_array($ev['mask'], $LISTEN_TYPE)) {
@@ -73,7 +71,6 @@ class Inotify
} }
//非重启类型 //非重启类型
if (str_ends_with($ev['name'], '.php')) { if (str_ends_with($ev['name'], '.php')) {
sleep(2);
$this->reload(); $this->reload();
} }
} }
@@ -84,7 +81,12 @@ class Inotify
*/ */
public function reload() public function reload()
{ {
if ($this->process->isReloading) {
return;
}
$this->process->isReloading = true; $this->process->isReloading = true;
$this->process->trigger_reload(); $this->process->trigger_reload();
$this->clearWatch(); $this->clearWatch();
foreach ($this->dirs as $root) { foreach ($this->dirs as $root) {
@@ -92,7 +94,6 @@ class Inotify
} }
$this->process->int = -1; $this->process->int = -1;
$this->process->isReloading = FALSE; $this->process->isReloading = FALSE;
$this->process->isReloadingOut = FALSE;
} }
+3
View File
@@ -103,6 +103,9 @@ class Scaner
*/ */
public function timerReload() public function timerReload()
{ {
if ($this->process->isReloading) {
return;
}
$this->process->isReloading = true; $this->process->isReloading = true;
$this->process->trigger_reload(); $this->process->trigger_reload();