改名
This commit is contained in:
@@ -2,9 +2,10 @@
|
|||||||
|
|
||||||
namespace Kiri\FileListen;
|
namespace Kiri\FileListen;
|
||||||
|
|
||||||
|
use Annotation\Inject;
|
||||||
use Exception;
|
use Exception;
|
||||||
use Kiri\Abstracts\Config;
|
use Kiri\Abstracts\Config;
|
||||||
use Kiri\Abstracts\Logger;
|
use Kiri\Error\Logger;
|
||||||
use Kiri\Exception\ConfigException;
|
use Kiri\Exception\ConfigException;
|
||||||
use Kiri\Kiri;
|
use Kiri\Kiri;
|
||||||
use Swoole\Coroutine;
|
use Swoole\Coroutine;
|
||||||
@@ -36,6 +37,10 @@ class HotReload extends Command
|
|||||||
public Inotify|Scaner $driver;
|
public Inotify|Scaner $driver;
|
||||||
|
|
||||||
|
|
||||||
|
#[Inject(Logger::class)]
|
||||||
|
public Logger $logger;
|
||||||
|
|
||||||
|
|
||||||
protected mixed $source = null;
|
protected mixed $source = null;
|
||||||
|
|
||||||
protected mixed $pipes = [];
|
protected mixed $pipes = [];
|
||||||
@@ -85,10 +90,12 @@ class HotReload extends Command
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param $data
|
||||||
|
* @throws Exception
|
||||||
|
*/
|
||||||
public function onSignal($data)
|
public function onSignal($data)
|
||||||
{
|
{
|
||||||
var_dump($data);
|
|
||||||
$this->driver->clear();
|
$this->driver->clear();
|
||||||
$pid = file_get_contents(storage('.swoole.pid'));
|
$pid = file_get_contents(storage('.swoole.pid'));
|
||||||
if (!empty($pid) && Process::kill($pid, 0)) {
|
if (!empty($pid) && Process::kill($pid, 0)) {
|
||||||
@@ -101,42 +108,6 @@ class HotReload extends Command
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @throws Exception
|
|
||||||
*/
|
|
||||||
public function onExit()
|
|
||||||
{
|
|
||||||
$data = Coroutine::waitSignal(SIGTERM | SIGKILL, -1);
|
|
||||||
if ($data) {
|
|
||||||
$pid = file_get_contents(storage('.swoole.pid'));
|
|
||||||
if (!empty($pid) && Process::kill($pid, 0)) {
|
|
||||||
Process::kill($pid, SIGTERM);
|
|
||||||
}
|
|
||||||
$this->stop();
|
|
||||||
$this->source = null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @throws Exception
|
|
||||||
*/
|
|
||||||
private function stop(): void
|
|
||||||
{
|
|
||||||
if (is_resource($this->source)) {
|
|
||||||
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 $code
|
||||||
* @param $message
|
* @param $message
|
||||||
@@ -160,13 +131,14 @@ class HotReload extends Command
|
|||||||
*/
|
*/
|
||||||
public function trigger_reload()
|
public function trigger_reload()
|
||||||
{
|
{
|
||||||
Kiri::getDi()->get(Logger::class)->warning('change reload');
|
$this->logger->warning('change reload');
|
||||||
if ($this->process instanceof Process && Process::kill($this->process->pid, 0)) {
|
if ($this->process instanceof Process && Process::kill($this->process->pid, 0)) {
|
||||||
$pid = file_get_contents(storage('.swoole.pid'));
|
$pid = file_get_contents(storage('.swoole.pid'));
|
||||||
if (!empty($pid) && Process::kill($pid, 0)) {
|
if (!empty($pid) && Process::kill($pid, 0)) {
|
||||||
Process::kill($pid, SIGTERM);
|
Process::kill($pid, SIGTERM);
|
||||||
}
|
}
|
||||||
Process::kill($this->process->pid, SIGTERM);
|
// Process::kill($this->process->pid, SIGTERM);
|
||||||
|
$this->process->exit(0);
|
||||||
Process::wait(true);
|
Process::wait(true);
|
||||||
}
|
}
|
||||||
$this->process = new Process(function (Process $process) {
|
$this->process = new Process(function (Process $process) {
|
||||||
|
|||||||
Reference in New Issue
Block a user