modifs.mineures sans commentaires

This commit is contained in:
Jephté Clain 2024-09-26 12:20:17 +04:00
parent 4bb386167f
commit b195888602
7 changed files with 26 additions and 24 deletions

View File

@ -65,7 +65,6 @@
}, },
"bin": [ "bin": [
"lib/_launch.php", "lib/_launch.php",
"bin/bg-launcher.php",
"nur_bin/compctl.php", "nur_bin/compctl.php",
"nur_bin/compdep.php", "nur_bin/compdep.php",
"nur_bin/cachectl.php", "nur_bin/cachectl.php",

View File

@ -21,7 +21,7 @@ class ExitError extends Error {
/** @var ?string */ /** @var ?string */
protected $userMessage; protected $userMessage;
function haveMessage(): bool { function haveUserMessage(): bool {
return $this->userMessage !== null; return $this->userMessage !== null;
} }

View File

@ -1,5 +1,5 @@
<?php <?php
namespace nur\sery\php\json; namespace nur\sery\ext\json;
use RuntimeException; use RuntimeException;

27
bin/bg-launcher.php → src/tools/BgLauncherApp.php Executable file → Normal file
View File

@ -1,21 +1,21 @@
#!/usr/bin/php
<?php <?php
require $_composer_autoload_path?? __DIR__.'/../vendor/autoload.php'; namespace nur\sery\tools;
use nur\sery\output\msg;
use nur\sery\wip\app\app2; use nur\sery\wip\app\app2;
use nur\sery\wip\app\cli\Application; use nur\sery\wip\app\cli\Application;
use nur\sery\wip\app\cli\bg_launcher; use nur\sery\wip\app\cli\bg_launcher;
use nur\yaml; use nur\yaml;
class BgLauncherApp extends Application { class BgLauncherApp extends Application {
const PROJDIR = __DIR__.'/../..';
const ACTION_INFOS = 0, ACTION_START = 1, ACTION_STOP = 2; const ACTION_INFOS = 0, ACTION_START = 1, ACTION_STOP = 2;
const ARGS = [ const ARGS = [
"purpose" => "lancer un script en tâche de fond", "purpose" => "lancer un script en tâche de fond",
"usage" => "ApplicationClass args...", "usage" => "ApplicationClass args...",
"sections" => [
parent::VERBOSITY_SECTION,
],
["-i", "--infos", "name" => "action", "value" => self::ACTION_INFOS, ["-i", "--infos", "name" => "action", "value" => self::ACTION_INFOS,
"help" => "Afficher des informations sur la tâche", "help" => "Afficher des informations sur la tâche",
], ],
@ -32,15 +32,16 @@ class BgLauncherApp extends Application {
protected ?array $args = null; protected ?array $args = null;
function main() { function main() {
$appClass = $this->args[0] ?? null; $args = $this->args;
$appClass = $args[0] ?? null;
if ($appClass === null) { if ($appClass === null) {
self::die("Vous devez spécifier la classe de l'application"); self::die("Vous devez spécifier la classe de l'application");
} }
$appClass = str_replace("/", "\\", $appClass); $appClass = $args[0] = str_replace("/", "\\", $appClass);
if (!class_exists($appClass)) { if (!class_exists($appClass)) {
self::die("$appClass: classe non trouvée"); self::die("$appClass: classe non trouvée");
} }
$args = array_slice($this->args, 1);
$useRunfile = constant("$appClass::USE_RUNFILE"); $useRunfile = constant("$appClass::USE_RUNFILE");
if (!$useRunfile) { if (!$useRunfile) {
@ -50,6 +51,12 @@ class BgLauncherApp extends Application {
$runfile = app2::with($appClass)->getRunfile(); $runfile = app2::with($appClass)->getRunfile();
switch ($this->action) { switch ($this->action) {
case self::ACTION_START: case self::ACTION_START:
$appClass::_manage_runfile(count($args), $args, $runfile);
array_splice($args, 0, 0, [
PHP_BINARY,
NULIB_APP_app_launcher,
]);
app2::params_putenv();
bg_launcher::_start($args, $runfile); bg_launcher::_start($args, $runfile);
break; break;
case self::ACTION_STOP: case self::ACTION_STOP:
@ -61,7 +68,3 @@ class BgLauncherApp extends Application {
} }
} }
} }
$params = app2::params_getenv();
if ($params !== null) app2::init($params);
BgLauncherApp::run();

View File

@ -482,7 +482,7 @@ class app2 {
const EC_DISABLED = 251; const EC_DISABLED = 251;
const EC_LOCKED = 252; const EC_LOCKED = 252;
const EC_BAD_COMMAND = 253; const EC_BAD_COMMAND = 253;
const EC_EXCEPTION = 254; const EC_UNEXPECTED = 254;
const EC_SIGNAL = 255; const EC_SIGNAL = 255;
############################################################################# #############################################################################

View File

@ -13,6 +13,7 @@ use nur\sery\output\std\StdMessenger;
use nur\sery\ValueException; use nur\sery\ValueException;
use nur\sery\wip\app\app2; use nur\sery\wip\app\app2;
use nur\sery\wip\app\RunFile; use nur\sery\wip\app\RunFile;
use nur\sery\wip\web\content\v;
/** /**
* Class Application: application de base * Class Application: application de base
@ -81,10 +82,9 @@ abstract class Application {
/** @var bool faut-il installer le gestionnaire de signaux? */ /** @var bool faut-il installer le gestionnaire de signaux? */
const USE_SIGNAL_HANDLER = false; const USE_SIGNAL_HANDLER = false;
static function _manage_runfile(RunFile $runfile): void { static function _manage_runfile(int $argc, array $argv, RunFile $runfile): void {
global $argc, $argv;
if ($argc <= 1 || $argv[1] !== "//") return; if ($argc <= 1 || $argv[1] !== "//") return;
array_splice($argv, 1, 1); $argc--; array_splice($argv, 1, 1);
$ec = 0; $ec = 0;
switch ($argv[1] ?? "infos") { switch ($argv[1] ?? "infos") {
case "release-lock": case "release-lock":
@ -104,7 +104,7 @@ abstract class Application {
} }
break; break;
default: default:
fwrite(STDERR, "$argv[2]: unexpected command\n"); fwrite(STDERR, "$argv[1]: unexpected command\n");
$ec = app2::EC_BAD_COMMAND; $ec = app2::EC_BAD_COMMAND;
} }
exit($ec); exit($ec);
@ -131,7 +131,8 @@ abstract class Application {
if ($useRunfile) { if ($useRunfile) {
$runfile = app2::get()->getRunfile(); $runfile = app2::get()->getRunfile();
self::_manage_runfile($runfile); global $argc, $argv;
self::_manage_runfile($argc, $argv, $runfile);
if ($useRunlock && $runfile->warnIfLocked()) exit(app2::EC_LOCKED); if ($useRunlock && $runfile->warnIfLocked()) exit(app2::EC_LOCKED);
$runfile->wfStart(); $runfile->wfStart();
@ -145,11 +146,11 @@ abstract class Application {
static::_configure_app($app); static::_configure_app($app);
static::_start_app($app); static::_start_app($app);
} catch (ExitError $e) { } catch (ExitError $e) {
if ($e->haveMessage()) msg::error($e); if ($e->haveUserMessage()) msg::error($e->getUserMessage());
exit($e->getCode()); exit($e->getCode());
} catch (Exception $e) { } catch (Exception $e) {
msg::error($e); msg::error($e);
exit(app2::EC_EXCEPTION); exit(app2::EC_UNEXPECTED);
} }
} }

View File

@ -6,7 +6,6 @@ use nur\sery\file\TmpfileWriter;
use nur\sery\os\path; use nur\sery\os\path;
use nur\sery\os\proc\Cmd; use nur\sery\os\proc\Cmd;
use nur\sery\output\msg; use nur\sery\output\msg;
use nur\sery\StateException;
use nur\sery\wip\app\app2; use nur\sery\wip\app\app2;
use nur\sery\wip\app\args; use nur\sery\wip\app\args;
use nur\sery\wip\app\RunFile; use nur\sery\wip\app\RunFile;