This commit is contained in:
2021-11-04 18:33:57 +08:00
parent affb161ddf
commit f6cb258259
2 changed files with 10 additions and 9 deletions
@@ -64,9 +64,6 @@ class FileChangeCustomProcess extends Command
$driver = Kiri::getDi()->get(Inotify::class, [$this->dirs, $this]);
}
$make = Barrier::make();
go(function () {
$this->source = proc_open('php ' . APP_PATH . 'kiri.php sw:server restart', [], $this->pipes);
});
go(function () {
$sign = Coroutine::waitSignal(SIGTERM, -1);
if ($sign) {
@@ -74,14 +71,15 @@ class FileChangeCustomProcess extends Command
}
});
go(function () use ($driver) {
$driver->start();
$this->source = proc_open('php ' . APP_PATH . 'kiri.php sw:server restart', [], $this->pipes);
$driver->start(Coroutine::getCid());
});
Barrier::wait($make);
return 0;
}
/**
* @param $code
* @param $message
@@ -102,10 +100,9 @@ class FileChangeCustomProcess extends Command
* 重启
* @throws Exception
*/
public function trigger_reload()
public function trigger_reload($cid)
{
Kiri::getDi()->get(Logger::class)->warning('change reload');
if (is_resource($this->source)) {
proc_close($this->source);
}
+6 -2
View File
@@ -13,6 +13,9 @@ class Inotify
private array $watchFiles = [];
protected int $cid;
const IG_DIR = [APP_PATH . 'commands', APP_PATH . '.git', APP_PATH . '.gitee'];
@@ -28,8 +31,9 @@ class Inotify
/**
* @throws Exception
*/
public function start()
public function start($cid)
{
$this->cid = $cid;
$this->inotify = inotify_init();
$this->events = IN_MODIFY | IN_DELETE | IN_CREATE | IN_MOVE;
foreach ($this->dirs as $dir) {
@@ -80,7 +84,7 @@ class Inotify
public function reload()
{
$this->process->isReloading = true;
$this->process->trigger_reload();
$this->process->trigger_reload($this->cid);
$this->clearWatch();
foreach ($this->dirs as $root) {