改名
This commit is contained in:
@@ -7,7 +7,6 @@ use Kiri\Abstracts\Config;
|
||||
use Kiri\Abstracts\Logger;
|
||||
use Kiri\Exception\ConfigException;
|
||||
use Kiri\Kiri;
|
||||
use Server\Constant;
|
||||
use Swoole\Coroutine;
|
||||
use Swoole\Process;
|
||||
use Symfony\Component\Console\Command\Command;
|
||||
@@ -31,6 +30,9 @@ class HotReload extends Command
|
||||
public int $int = -1;
|
||||
|
||||
|
||||
private ?Process $process = null;
|
||||
|
||||
|
||||
protected mixed $source = null;
|
||||
|
||||
protected mixed $pipes = [];
|
||||
@@ -70,10 +72,18 @@ class HotReload extends Command
|
||||
swoole_set_process_name('[' . Config::get('id', 'sw service.') . '].sw:wather');
|
||||
}
|
||||
$this->trigger_reload();
|
||||
Coroutine::create(fn() => $this->onExit());
|
||||
Coroutine::create(function () use ($driver) {
|
||||
$driver->start();
|
||||
Process::signal(SIGTERM | SIGKILL, function ($data) {
|
||||
var_dump($data);
|
||||
$pid = file_get_contents(storage('.swoole.pid'));
|
||||
if (!empty($pid) && Process::kill($pid, 0)) {
|
||||
Process::kill($pid, SIGTERM);
|
||||
}
|
||||
while ($ret = Process::wait(true)) {
|
||||
echo "PID={$ret['pid']}\n";
|
||||
sleep(1);
|
||||
}
|
||||
});
|
||||
$driver->start();
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -104,12 +114,16 @@ class HotReload extends Command
|
||||
proc_terminate($this->source);
|
||||
while (proc_get_status($this->source)['running']) {
|
||||
Coroutine::sleep(1);
|
||||
var_dump(proc_get_status($this->source)['running']);
|
||||
}
|
||||
var_dump(proc_get_status($this->source)['running']);
|
||||
proc_close($this->source);
|
||||
var_dump('isClose.');
|
||||
$this->source = null;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param $code
|
||||
* @param $message
|
||||
@@ -134,20 +148,18 @@ class HotReload extends Command
|
||||
public function trigger_reload()
|
||||
{
|
||||
Kiri::getDi()->get(Logger::class)->warning('change reload');
|
||||
Coroutine::create(function () {
|
||||
$reusePort = Config::get('server.settings')[Constant::OPTION_ENABLE_REUSE_PORT] ?? false;
|
||||
if (!$reusePort) {
|
||||
$this->source = proc_open("php " . APP_PATH . "kiri.php sw:server", [], $pipes);
|
||||
return;
|
||||
}
|
||||
if ($this->process instanceof Process && Process::kill($this->process->pid, 0)) {
|
||||
$pid = file_get_contents(storage('.swoole.pid'));
|
||||
$source = proc_open("php " . APP_PATH . "kiri.php sw:server start", [], $pipes);
|
||||
if (!empty($pid) && Process::kill($pid, 0)) {
|
||||
Process::kill($pid, SIGTERM);
|
||||
}
|
||||
$this->stop();
|
||||
$this->source = $source;
|
||||
Process::kill($this->process->pid, SIGTERM);
|
||||
Process::wait(true);
|
||||
}
|
||||
$this->process = new Process(function (Process $process) {
|
||||
$process->exec(PHP_BINARY, [APP_PATH . "kiri.php", "sw:server", "restart"]);
|
||||
});
|
||||
$this->process->start();
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user