This commit is contained in:
2021-11-05 10:58:34 +08:00
parent 2c0a431069
commit 49ac53e751
@@ -8,13 +8,10 @@ use Kiri\Abstracts\Logger;
use Kiri\Exception\ConfigException; use Kiri\Exception\ConfigException;
use Kiri\Kiri; use Kiri\Kiri;
use Swoole\Coroutine; use Swoole\Coroutine;
use Swoole\Coroutine\Barrier;
use Swoole\Process; use Swoole\Process;
use Symfony\Component\Console\Command\Command; use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface; use Symfony\Component\Console\Output\OutputInterface;
use function Co\run;
/** /**
@@ -69,11 +66,38 @@ class FileChangeCustomProcess extends Command
$this->trigger_reload(); $this->trigger_reload();
Coroutine::create(function () use ($driver) { Coroutine::create(function () use ($driver) {
Coroutine::create(function () {
$waite = Coroutine::waitSignal(SIGTERM | SIGKILL);
if ($waite) {
$this->stop();
}
});
$driver->start(); $driver->start();
}); });
return 0; return 0;
} }
/**
* @throws Exception
*/
private function stop(): void
{
if (!file_exists(storage('.swoole.pid'))) {
return;
}
$content = (int)file_get_contents(storage('.swoole.pid'));
if ($content > 0 && Process::kill($content, 0)) {
Process::kill($content, 15);
}
@unlink(storage('.swoole.pid'));
if (is_resource($this->source)) {
proc_close($this->source);
$this->source = null;
}
}
/** /**
* @param $code * @param $code
* @param $message * @param $message
@@ -101,8 +125,8 @@ class FileChangeCustomProcess extends Command
if (file_exists(storage('.swoole.pid'))) { if (file_exists(storage('.swoole.pid'))) {
$content = (int)file_get_contents(storage('.swoole.pid')); $content = (int)file_get_contents(storage('.swoole.pid'));
if ($content > 0 && Process::kill($content,0)){ if ($content > 0 && Process::kill($content, 0)) {
Process::kill($content,15); Process::kill($content, 15);
} }
@unlink(storage('.swoole.pid')); @unlink(storage('.swoole.pid'));
@@ -119,8 +143,4 @@ class FileChangeCustomProcess extends Command
} }
} }