diff --git a/.idea/nur-sery.iml b/.idea/nur-sery.iml
index 74e150b..835a401 100644
--- a/.idea/nur-sery.iml
+++ b/.idea/nur-sery.iml
@@ -8,7 +8,7 @@
-
+
diff --git a/composer.json b/composer.json
index 698923c..4f48034 100644
--- a/composer.json
+++ b/composer.json
@@ -50,8 +50,7 @@
"autoload": {
"psr-4": {
"nur\\sery\\wip\\": "wip",
- "nur\\sery\\app\\": "wip_app",
- "nur\\sery\\": "src",
+ "nur\\sery\\": ["wip_app", "src"],
"nur\\": "nur_src"
},
"files": [
diff --git a/nur_src/cli/Application.php b/nur_src/cli/Application.php
index 65f975d..9bd4ee8 100644
--- a/nur_src/cli/Application.php
+++ b/nur_src/cli/Application.php
@@ -9,25 +9,18 @@ use nur\config\ArrayConfig;
use nur\msg;
use nur\os;
use nur\path;
-use nur\sery\app\launcher;
-use nur\sery\app\RunFile;
-use nur\sery\cl;
use nur\sery\app;
+use nur\sery\app\RunFile;
+use nur\sery\output\console as nconsole;
use nur\sery\output\log as nlog;
use nur\sery\output\msg as nmsg;
-use nur\sery\output\console as nconsole;
use nur\sery\output\std\StdMessenger;
+use nur\yaml;
/**
* Class Application: application de base
*/
abstract class Application {
- protected static ?array $internal_use_app_params = null;
-
- static function internal_use_set_app_params($params) {
- self::$internal_use_app_params = $params;
- }
-
/** @var string répertoire du projet (celui qui contient composer.json */
const PROJDIR = null;
@@ -46,6 +39,13 @@ abstract class Application {
*/
const APPCODE = null;
+ /**
+ * @var string|null identifiant d'un groupe auquel l'application appartient.
+ * les applications du même groupe enregistrent leur fichiers de controle au
+ * même endroit $VARDIR/$APPGROUP
+ */
+ const APPGROUP = null;
+
/**
* @var string code de l'application, utilisé pour inférer le nom de certains
* fichiers spécifiques à l'application.
@@ -78,7 +78,74 @@ abstract class Application {
const USE_RUNLOCK = false;
/** @var bool faut-il installer le gestionnaire de signaux? */
- const USE_SIGNAL_HANDLER = false;
+ const INSTALL_SIGNAL_HANDLER = false;
+
+ private static function _info(string $message, int $ec=0): int {
+ fwrite(STDERR, "INFO: $message\n");
+ return $ec;
+ }
+
+ private static function _error(string $message, int $ec=1): int {
+ fwrite(STDERR, "ERROR: $message\n");
+ return $ec;
+ }
+
+ static function _manage_runfile(int &$argc, array &$argv, RunFile $runfile): void {
+ if ($argc <= 1 || $argv[1] !== "//") return;
+ array_splice($argv, 1, 1); $argc--;
+ $ec = 0;
+ switch ($argv[1] ?? "infos") {
+ case "help":
+ self::_info(<<getDesc();
+ if ($runfile->isRunning()) {
+ $actionDesc = $runfile->getActionDesc();
+ if ($actionDesc !== null) $actionDesc = "\n$actionDesc";
+ echo "$desc$actionDesc\n";
+ } else {
+ echo "$desc\n";
+ $ec = 1;
+ }
+ break;
+ case "dump":
+ case "d":
+ yaml::dump($runfile->read());
+ break;
+ case "reset":
+ case "z":
+ if (!$runfile->isRunning()) $runfile->reset();
+ else $ec = self::_error("cannot reset while running");
+ break;
+ case "release":
+ case "rl":
+ $runfile->release();
+ break;
+ case "start":
+ case "s":
+ array_splice($argv, 1, 1); $argc--;
+ return;
+ case "kill":
+ case "k":
+ if ($runfile->isRunning()) $runfile->wfKill();
+ else $ec = self::_error("not running");
+ break;
+ default:
+ $ec = self::_error("$argv[1]: unexpected command", app::EC_BAD_COMMAND);
+ }
+ exit($ec);
+ }
protected static function _app_init(): void {
config::set_fact(config::FACT_CLI_APP);
@@ -108,7 +175,7 @@ abstract class Application {
if ($projdir == "/") break;
}
- app::init(static::class, self::$internal_use_app_params);
+ app::init(static::class);
nmsg::set_messenger(new StdMessenger([
"min_level" => nmsg::DEBUG,
]));
@@ -146,7 +213,7 @@ abstract class Application {
static function run(?Application $app=null): void {
$unlock = false;
$stop = false;
- $shutdownHandler = function () use (&$unlock, &$stop) {
+ $shutdown = function () use (&$unlock, &$stop) {
if ($unlock) {
app::get()->getRunfile()->release();
$unlock = false;
@@ -156,29 +223,19 @@ abstract class Application {
$stop = false;
}
};
- register_shutdown_function($shutdownHandler);
- if (static::USE_SIGNAL_HANDLER) {
- $signalHandler = function(int $signo, $siginfo) {
- self::exit(255);
- };
- pcntl_signal(SIGHUP, $signalHandler);
- pcntl_signal(SIGINT, $signalHandler);
- pcntl_signal(SIGQUIT, $signalHandler);
- pcntl_signal(SIGTERM, $signalHandler);
- }
+ register_shutdown_function($shutdown);
+ app::install_signal_handler(static::INSTALL_SIGNAL_HANDLER);
try {
static::_app_init();
- if (static::USE_RUNFILE) {
+ $useRunfile = static::USE_RUNFILE;
+ $useRunlock = static::USE_RUNLOCK;
+ if ($useRunfile) {
$runfile = app::get()->getRunfile();
+
global $argc, $argv;
- if ($argc === 2 && ($argv[1] === "--Application-release-runlock" || $argv[1] === "--ARL")) {
- $runfile->release();
- exit(0);
- }
- $useRunlock = static::USE_RUNLOCK;
- if ($useRunlock && $runfile->warnIfLocked()) {
- exit(1);
- }
+ self::_manage_runfile($argc, $argv, $runfile);
+ if ($useRunlock && $runfile->warnIfLocked()) exit(app::EC_LOCKED);
+
$runfile->wfStart();
$stop = true;
if ($useRunlock) {
@@ -393,15 +450,4 @@ abstract class Application {
}
abstract function main();
-
- const BGLAUNCH_SCRIPT = null;
- static function runfile(): RunFile {
- $callerParams = app::get()->getParams();
- return app::with(static::class, $callerParams)->getRunfile();
- }
- static function bglaunch(?array $args=null) {
- launcher::launch(static::class, cl::merge([
- static::BGLAUNCH_SCRIPT,
- ], $args));
- }
}
diff --git a/src/app.php b/wip_app/app.php
similarity index 98%
rename from src/app.php
rename to wip_app/app.php
index 0e1f04f..1fc12bf 100644
--- a/src/app.php
+++ b/wip_app/app.php
@@ -1,6 +1,7 @@
invoke());
- if (!$forceEnabled && !$enabled) {
+ if (self::$bgapplication_enabled === null || $forceEnabled) return;
+ if (!self::$bgapplication_enabled->invoke()) {
throw new ExitError(self::EC_DISABLED, "Planifications désactivées. La tâche n'a pas été lancée");
}
}
diff --git a/wip_app/cli/Application.php b/wip_app/app/cli/Application.php
similarity index 100%
rename from wip_app/cli/Application.php
rename to wip_app/app/cli/Application.php
diff --git a/wip_app/cli/TODO.md b/wip_app/app/cli/TODO.md
similarity index 100%
rename from wip_app/cli/TODO.md
rename to wip_app/app/cli/TODO.md