This commit is contained in:
2021-11-19 02:54:05 +08:00
parent 841a6b4a19
commit 0a6fdda720
+17 -12
View File
@@ -21,8 +21,8 @@ class HotReload extends Command
{
public bool $isReloading = false;
public bool $isReloadingOut = false;
public bool $isReloading = FALSE;
public bool $isReloadingOut = FALSE;
public ?array $dirs = [];
public int $events;
@@ -30,14 +30,14 @@ class HotReload extends Command
public int $int = -1;
private ?Process $process = null;
private ?Process $process = NULL;
protected mixed $source = null;
protected mixed $source = NULL;
protected mixed $pipes = [];
protected ?Coroutine\Channel $channel = null;
protected ?Coroutine\Channel $channel = NULL;
/**
@@ -72,15 +72,20 @@ class HotReload extends Command
swoole_set_process_name('[' . Config::get('id', 'sw service.') . '].sw:wather');
}
$this->trigger_reload();
pcntl_signal(SIGTERM | SIGKILL, function ($data) {
Process::signal(SIGKILL, [$this, 'onSignal']);
Process::signal(SIGTERM, [$this, 'onSignal']);
$driver->start();
return 0;
}
public function onSignal($data)
{
var_dump($data);
$pid = file_get_contents(storage('.swoole.pid'));
if (!empty($pid) && Process::kill($pid, 0)) {
Process::kill($pid, SIGTERM);
}
});
$driver->start();
return 0;
}
@@ -96,7 +101,7 @@ class HotReload extends Command
Process::kill($pid, SIGTERM);
}
$this->stop();
$this->source = null;
$this->source = NULL;
}
}
@@ -115,7 +120,7 @@ class HotReload extends Command
var_dump(proc_get_status($this->source)['running']);
proc_close($this->source);
var_dump('isClose.');
$this->source = null;
$this->source = NULL;
}
}
@@ -150,7 +155,7 @@ class HotReload extends Command
Process::kill($pid, SIGTERM);
}
Process::kill($this->process->pid, SIGTERM);
Process::wait(true);
Process::wait(TRUE);
}
$this->process = new Process(function (Process $process) {
$process->exec(PHP_BINARY, [APP_PATH . "kiri.php", "sw:server", "restart"]);