modifs.mineures sans commentaires
This commit is contained in:
parent
4686fd07d4
commit
bd10883740
|
@ -88,18 +88,20 @@ class BgLauncherApp extends Application {
|
|||
} elseif (!$pid) {
|
||||
# child, fork ok
|
||||
$runfile->wfPrepare($pid);
|
||||
$logfile = $runfile->getLogfile() ?? "/tmp/NULIB_APP_app_console.log";
|
||||
$outfile = $runfile->getOutfile() ?? "/tmp/NULIB_APP_app_console.out";
|
||||
$exitcode = app2::EC_FORK_CHILD;
|
||||
try {
|
||||
# rediriger STDOUT et STDERR
|
||||
# rediriger STDIN, STDOUT et STDERR
|
||||
fclose(STDIN);
|
||||
$in = fopen("/dev/null", "rb");
|
||||
fclose(STDOUT);
|
||||
$out = fopen($logfile, "a+b");
|
||||
$out = fopen($outfile, "a+b");
|
||||
fclose(STDERR);
|
||||
$err = fopen($logfile, "a+b");
|
||||
$err = fopen($outfile, "a+b");
|
||||
# puis lancer la commande
|
||||
$cmd = new Cmd($args);
|
||||
$cmd->addSource("/g/init.env");
|
||||
$cmd->addRedir("both", $logfile, true);
|
||||
$cmd->addRedir("both", $outfile, true);
|
||||
$cmd->fork_exec($exitcode, false);
|
||||
sh::_waitpid(-$pid, $exitcode);
|
||||
} finally {
|
||||
|
|
|
@ -21,21 +21,21 @@ class RunFile {
|
|||
|
||||
const NAME = null;
|
||||
|
||||
function __construct(?string $name, string $file, ?string $logfile=null) {
|
||||
function __construct(?string $name, string $file, ?string $outfile=null) {
|
||||
$file = path::ensure_ext($file, self::RUN_EXT);
|
||||
$this->name = $name ?? static::NAME;
|
||||
$this->file = new SharedFile($file);
|
||||
$this->logfile = $logfile;
|
||||
$this->outfile = $outfile;
|
||||
}
|
||||
|
||||
protected ?string $name;
|
||||
|
||||
protected SharedFile $file;
|
||||
|
||||
protected ?string $logfile;
|
||||
protected ?string $outfile;
|
||||
|
||||
function getLogfile(): ?string {
|
||||
return $this->logfile;
|
||||
function getOutfile(): ?string {
|
||||
return $this->outfile;
|
||||
}
|
||||
|
||||
protected static function merge(array $data, array $merge): array {
|
||||
|
@ -47,7 +47,6 @@ class RunFile {
|
|||
protected function initData(): array {
|
||||
return [
|
||||
"name" => $this->name,
|
||||
"mode" => null,
|
||||
"pgid" => null,
|
||||
"pid" => null,
|
||||
"serial" => 0,
|
||||
|
@ -56,7 +55,7 @@ class RunFile {
|
|||
"date_lock" => null,
|
||||
"date_release" => null,
|
||||
# run
|
||||
"logfile" => $this->logfile,
|
||||
"logfile" => $this->outfile,
|
||||
"date_start" => null,
|
||||
"date_stop" => null,
|
||||
"exitcode" => null,
|
||||
|
@ -178,7 +177,6 @@ class RunFile {
|
|||
posix_setsid();
|
||||
$pgid = posix_getpid();
|
||||
return cl::merge($this->initData(), [
|
||||
"mode" => "session",
|
||||
"pgid" => $pgid,
|
||||
"pid" => null,
|
||||
"date_start" => new DateTime(),
|
||||
|
@ -190,13 +188,12 @@ class RunFile {
|
|||
function wfStart(): void {
|
||||
$this->update(function (array $data) {
|
||||
$pid = posix_getpid();
|
||||
if ($data["mode"] === "session") {
|
||||
if ($data["pgid"] !== null) {
|
||||
A::merge($data, [
|
||||
"pid" => $pid,
|
||||
]);
|
||||
} else {
|
||||
$data = cl::merge($this->initData(), [
|
||||
"mode" => "standalone",
|
||||
"pid" => $pid,
|
||||
"date_start" => new DateTime(),
|
||||
]);
|
||||
|
@ -218,7 +215,7 @@ class RunFile {
|
|||
}
|
||||
|
||||
function _getCid(array $data=null): int {
|
||||
if ($data["mode"] === "session") return -$data["pgid"];
|
||||
if ($data["pgid"] !== null) return -$data["pgid"];
|
||||
else return $data["pid"];
|
||||
}
|
||||
|
||||
|
@ -276,7 +273,6 @@ class RunFile {
|
|||
function wfReaped(int $exitcode): void {
|
||||
$this->update(function (array $data) use ($exitcode) {
|
||||
return [
|
||||
"mode" => null,
|
||||
"pgid" => null,
|
||||
"date_stop" => $data["date_stop"] ?? new DateTime(),
|
||||
"exitcode" => $exitcode,
|
||||
|
|
Loading…
Reference in New Issue