From d744775ccc7c058ded096c29bdd09a89ea492c65 Mon Sep 17 00:00:00 2001 From: Jephte Clain Date: Mon, 17 Jun 2024 21:55:07 +0400 Subject: [PATCH] modifs.mineures sans commentaires --- src/app/RunFile.php | 28 +++++++++++++++++++--------- src/app/launcher.php | 5 +++-- src/wip/app/app.php | 11 +++++++---- 3 files changed, 29 insertions(+), 15 deletions(-) diff --git a/src/app/RunFile.php b/src/app/RunFile.php index 0a3f20c..1818213 100644 --- a/src/app/RunFile.php +++ b/src/app/RunFile.php @@ -18,17 +18,22 @@ class RunFile { const NAME = null; - function __construct(string $file, ?string $name=null) { + function __construct(?string $name, string $file, ?string $logfile=null) { $file = path::ensure_ext($file, self::RUN_EXT); - $this->file = new SharedFile($file); $this->name = $name ?? static::NAME; + $this->file = new SharedFile($file); + $this->logfile = $logfile; } - /** @var SharedFile */ - protected $file; + protected ?string $name; - /** @var ?string */ - protected $name; + protected SharedFile $file; + + protected ?string $logfile; + + function getLogfile(): ?string { + return $this->logfile; + } protected static function merge(array $data, array $merge): array { return cl::merge($data, [ @@ -36,9 +41,13 @@ class RunFile { ], $merge); } - protected function initData(bool $withDateStart=true): array { - $pid = $withDateStart? posix_getpid(): null; - $dateStart = $withDateStart? new DateTime(): null; + protected function initData(bool $forStart=true): array { + if ($forStart) { + $pid = posix_getpid(); + $dateStart = new DateTime(); + } else { + $pid = $dateStart = null; + } return [ "name" => $this->name, "id" => bin2hex(random_bytes(16)), @@ -50,6 +59,7 @@ class RunFile { "date_lock" => null, "date_release" => null, # run + "logfile" => $this->logfile, "date_start" => $dateStart, "date_stop" => null, "exitcode" => null, diff --git a/src/app/launcher.php b/src/app/launcher.php index 181d1a2..e77788b 100644 --- a/src/app/launcher.php +++ b/src/app/launcher.php @@ -59,7 +59,7 @@ class launcher { "--internal-use", $tmpfile->getFile(), $appClass, "--", ...$args, ]); - $cmd->addRedir("both", "/tmp/_nulib_launch-launcher.log"); + $cmd->addRedir("both", "/tmp/nulib_app_launcher-launch.log"); $cmd->passthru($exitcode); # attendre un peu que la commande aie le temps de s'initialiser @@ -82,13 +82,14 @@ class launcher { ## child, fork ok # Créer un groupe de process, pour pouvoir les tuer toutes en même temps $runfile->tm_startPg(); + $logfile = $runfile->getLogfile() ?? "/tmp/nulib_app_launcher-_start.log"; $pid = posix_getpid(); $exitcode = -776; try { # puis lancer la commande $cmd = new Cmd($args); $cmd->addSource("/g/init.env"); - $cmd->addRedir("both", "/tmp/_nulib_launch-app.log"); + $cmd->addRedir("both", $logfile); #XXX prendre le fichier de log de $runfile si possible? msg::debug("$pid: launching\n".$cmd->getCmd()); $cmd->fork_exec($exitcode); diff --git a/src/wip/app/app.php b/src/wip/app/app.php index ab993f9..237aed0 100644 --- a/src/wip/app/app.php +++ b/src/wip/app/app.php @@ -351,12 +351,15 @@ class app { function getRunfile(): RunFile { $name = $this->name; - return $this->runfile ??= new RunFile($this->getWorkfile($name), $name); + $runfile = $this->getWorkfile($name); + $logfile = $this->getLogfile(); + return $this->runfile ??= new RunFile($name, $runfile, $logfile); } - protected ?LockFile $lockFile = null; + protected ?array $lockFiles = null; - function getLockfile(): LockFile { - return $this->lockFile ??= $this->getRunfile()->getLockFile(null, $this->title); + function getLockfile(?string $name=null): LockFile { + $this->lockFiles[$name] ??= $this->getRunfile()->getLockFile($name, $this->title); + return $this->lockFiles[$name]; } }