modifs.mineures sans commentaires
This commit is contained in:
parent
218c097cc4
commit
d744775ccc
|
@ -18,17 +18,22 @@ class RunFile {
|
||||||
|
|
||||||
const NAME = null;
|
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);
|
$file = path::ensure_ext($file, self::RUN_EXT);
|
||||||
$this->file = new SharedFile($file);
|
|
||||||
$this->name = $name ?? static::NAME;
|
$this->name = $name ?? static::NAME;
|
||||||
|
$this->file = new SharedFile($file);
|
||||||
|
$this->logfile = $logfile;
|
||||||
}
|
}
|
||||||
|
|
||||||
/** @var SharedFile */
|
protected ?string $name;
|
||||||
protected $file;
|
|
||||||
|
|
||||||
/** @var ?string */
|
protected SharedFile $file;
|
||||||
protected $name;
|
|
||||||
|
protected ?string $logfile;
|
||||||
|
|
||||||
|
function getLogfile(): ?string {
|
||||||
|
return $this->logfile;
|
||||||
|
}
|
||||||
|
|
||||||
protected static function merge(array $data, array $merge): array {
|
protected static function merge(array $data, array $merge): array {
|
||||||
return cl::merge($data, [
|
return cl::merge($data, [
|
||||||
|
@ -36,9 +41,13 @@ class RunFile {
|
||||||
], $merge);
|
], $merge);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function initData(bool $withDateStart=true): array {
|
protected function initData(bool $forStart=true): array {
|
||||||
$pid = $withDateStart? posix_getpid(): null;
|
if ($forStart) {
|
||||||
$dateStart = $withDateStart? new DateTime(): null;
|
$pid = posix_getpid();
|
||||||
|
$dateStart = new DateTime();
|
||||||
|
} else {
|
||||||
|
$pid = $dateStart = null;
|
||||||
|
}
|
||||||
return [
|
return [
|
||||||
"name" => $this->name,
|
"name" => $this->name,
|
||||||
"id" => bin2hex(random_bytes(16)),
|
"id" => bin2hex(random_bytes(16)),
|
||||||
|
@ -50,6 +59,7 @@ class RunFile {
|
||||||
"date_lock" => null,
|
"date_lock" => null,
|
||||||
"date_release" => null,
|
"date_release" => null,
|
||||||
# run
|
# run
|
||||||
|
"logfile" => $this->logfile,
|
||||||
"date_start" => $dateStart,
|
"date_start" => $dateStart,
|
||||||
"date_stop" => null,
|
"date_stop" => null,
|
||||||
"exitcode" => null,
|
"exitcode" => null,
|
||||||
|
|
|
@ -59,7 +59,7 @@ class launcher {
|
||||||
"--internal-use", $tmpfile->getFile(),
|
"--internal-use", $tmpfile->getFile(),
|
||||||
$appClass, "--", ...$args,
|
$appClass, "--", ...$args,
|
||||||
]);
|
]);
|
||||||
$cmd->addRedir("both", "/tmp/_nulib_launch-launcher.log");
|
$cmd->addRedir("both", "/tmp/nulib_app_launcher-launch.log");
|
||||||
$cmd->passthru($exitcode);
|
$cmd->passthru($exitcode);
|
||||||
|
|
||||||
# attendre un peu que la commande aie le temps de s'initialiser
|
# attendre un peu que la commande aie le temps de s'initialiser
|
||||||
|
@ -82,13 +82,14 @@ class launcher {
|
||||||
## child, fork ok
|
## child, fork ok
|
||||||
# Créer un groupe de process, pour pouvoir les tuer toutes en même temps
|
# Créer un groupe de process, pour pouvoir les tuer toutes en même temps
|
||||||
$runfile->tm_startPg();
|
$runfile->tm_startPg();
|
||||||
|
$logfile = $runfile->getLogfile() ?? "/tmp/nulib_app_launcher-_start.log";
|
||||||
$pid = posix_getpid();
|
$pid = posix_getpid();
|
||||||
$exitcode = -776;
|
$exitcode = -776;
|
||||||
try {
|
try {
|
||||||
# puis lancer la commande
|
# puis lancer la commande
|
||||||
$cmd = new Cmd($args);
|
$cmd = new Cmd($args);
|
||||||
$cmd->addSource("/g/init.env");
|
$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?
|
#XXX prendre le fichier de log de $runfile si possible?
|
||||||
msg::debug("$pid: launching\n".$cmd->getCmd());
|
msg::debug("$pid: launching\n".$cmd->getCmd());
|
||||||
$cmd->fork_exec($exitcode);
|
$cmd->fork_exec($exitcode);
|
||||||
|
|
|
@ -351,12 +351,15 @@ class app {
|
||||||
|
|
||||||
function getRunfile(): RunFile {
|
function getRunfile(): RunFile {
|
||||||
$name = $this->name;
|
$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 {
|
function getLockfile(?string $name=null): LockFile {
|
||||||
return $this->lockFile ??= $this->getRunfile()->getLockFile(null, $this->title);
|
$this->lockFiles[$name] ??= $this->getRunfile()->getLockFile($name, $this->title);
|
||||||
|
return $this->lockFiles[$name];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue