diff --git a/src/tools/BgLauncherApp.php b/src/tools/BgLauncherApp.php index b689824..49c3757 100644 --- a/src/tools/BgLauncherApp.php +++ b/src/tools/BgLauncherApp.php @@ -1,11 +1,13 @@ wfPrepare($pid); + $logfile = $runfile->getLogfile() ?? "/tmp/NULIB_APP_app_console.log"; + $exitcode = app2::EC_FORK_CHILD; + try { + # rediriger STDOUT et STDERR + fclose(STDOUT); + $out = fopen($logfile, "a+b"); + fclose(STDERR); + $err = fopen($logfile, "a+b"); + # puis lancer la commande + $cmd = new Cmd($args); + $cmd->addSource("/g/init.env"); + $cmd->addRedir("both", $logfile, true); + $cmd->fork_exec($exitcode, false); + sh::_waitpid(-$pid, $exitcode); + } finally { + $runfile->wfReaped($exitcode); + } + } + } + + public static function _stop(Runfile $runfile): bool { + $data = $runfile->read(); + $pid = $runfile->_getCid($data); + msg::action("stop $pid"); + if ($runfile->wfKill($reason)) { + msg::asuccess(); + return true; + } else { + msg::afailure($reason); + return false; + } + } } diff --git a/src/tools/SteamTrainApp.php b/src/tools/SteamTrainApp.php index fe00715..75cd41e 100644 --- a/src/tools/SteamTrainApp.php +++ b/src/tools/SteamTrainApp.php @@ -2,6 +2,8 @@ namespace nur\sery\tools; use nur\sery\output\msg; +use nur\sery\php\time\DateTime; +use nur\sery\text\words; use nur\sery\wip\app\app2; use nur\sery\wip\app\cli\Application; @@ -33,11 +35,13 @@ EOT, function main() { if ($this->installSignalHandler) app2::install_signal_handler(); $count = intval($this->count); + msg::info("Starting train for ".words::q($count, "step#s")); app2::action("Running train...", $count); for ($i = 1; $i <= $count; $i++) { msg::print("Tchou-tchou! x $i"); app2::step(); sleep(1); } + msg::info("Stopping train at ".new DateTime()); } } diff --git a/wip/app/app2.php b/wip/app/app2.php index d10508d..8a5a6ed 100644 --- a/wip/app/app2.php +++ b/wip/app/app2.php @@ -463,7 +463,7 @@ class app2 { $name = $this->name; $runfile = $this->getWorkfile($name); # ne pas spécifier $name pour avoir le fichier par défaut sans profil - $logfile = $this->getLogfile(); + $logfile = $this->getLogfile("$name.console.log", false); return $this->runfile ??= new RunFile($name, $runfile, $logfile); } diff --git a/wip/app/cli/bg_launcher.php b/wip/app/cli/bg_launcher.php deleted file mode 100644 index 3948e99..0000000 --- a/wip/app/cli/bg_launcher.php +++ /dev/null @@ -1,47 +0,0 @@ -wfPrepare($pid); - $logfile = $runfile->getLogfile() ?? "/tmp/NULIB_APP_app_start.log"; - $exitcode = app2::EC_FORK_CHILD; - try { - # puis lancer la commande - $cmd = new Cmd($args); - $cmd->addSource("/g/init.env"); - $cmd->addRedir("both", $logfile, true); - $cmd->fork_exec($exitcode, false); - sh::_waitpid(-$pid, $exitcode); - } finally { - $runfile->wfReaped($exitcode); - } - } - } - - static function _stop(Runfile $runfile): bool { - $data = $runfile->read(); - $pid = $runfile->_getCid($data); - msg::action("stop $pid"); - if ($runfile->wfKill($reason)) { - msg::asuccess(); - return true; - } else { - msg::afailure($reason); - return false; - } - } -}