diff --git a/nur_src/cli/Application.php b/nur_src/cli/Application.php index d54b486..9fa7749 100644 --- a/nur_src/cli/Application.php +++ b/nur_src/cli/Application.php @@ -454,4 +454,8 @@ EOT); } abstract function main(); + + static function runfile(): RunFile { + return app::with(static::class)->getRunfile(); + } } diff --git a/src/app/cli/template-wrapper.sh b/src/app/cli/template-wrapper.sh index 9c92553..95506e5 100755 --- a/src/app/cli/template-wrapper.sh +++ b/src/app/cli/template-wrapper.sh @@ -32,6 +32,8 @@ launcher="$MYTRUEDIR/$LAUNCHERPATH" class="$MYTRUEDIR${WRAPPEDPATH:+/$WRAPPEDPATH}/${MYNAME%.php}.phpc" script="$MYTRUEDIR${WRAPPEDPATH:+/$WRAPPEDPATH}/${MYNAME%.php}.php" +[ -f /g/init.env ] && source /g/init.env + www_data="${DEVUSER_USERENT%%:*}" [ -n "$www_data" ] || www_data=www-data diff --git a/src/db/sqlite/SqliteStorage.php b/src/db/sqlite/SqliteStorage.php index 92f77fc..b6f9ac0 100644 --- a/src/db/sqlite/SqliteStorage.php +++ b/src/db/sqlite/SqliteStorage.php @@ -30,25 +30,41 @@ class SqliteStorage extends CapacitorStorage { protected function _afterCreate(CapacitorChannel $channel): void { $db = $this->db; - $db->exec([ - "create table if not exists", - "table" => "_channels", - "cols" => [ - "name" => "varchar primary key", - "table_name" => "varchar", - "class" => "varchar", - ], + $name = $this->db->get([ + "select name from sqlite_schema", + "where" => ["name" => "_channels"], ]); - $db->exec([ - "insert", - "into" => "_channels", - "values" => [ - "name" => $channel->getName(), - "table_name" => $channel->getTableName(), - "class" => get_class($channel), - ], - "suffix" => "on conflict do nothing", + if ($name === null) { + # ne pas créer si la table existe déjà, pour éviter d'avoir besoin d'un + # verrou en écriture + $db->exec([ + "create table if not exists", + "table" => "_channels", + "cols" => [ + "name" => "varchar primary key", + "table_name" => "varchar", + "class" => "varchar", + ], + ]); + } + $name = $this->db->get([ + "select name from _channels", + "where" => ["name" => $channel->getName()], ]); + if ($name === null) { + # ne pas insérer si la ligne existe déjà, pour éviter d'avoir besoin d'un + # verrou en écriture + $db->exec([ + "insert", + "into" => "_channels", + "values" => [ + "name" => $channel->getName(), + "table_name" => $channel->getTableName(), + "class" => get_class($channel), + ], + "suffix" => "on conflict do nothing", + ]); + } } protected function _beforeReset(CapacitorChannel $channel): void { diff --git a/src/tools/BgLauncherApp.php b/src/tools/BgLauncherApp.php index 971c993..2a6408c 100644 --- a/src/tools/BgLauncherApp.php +++ b/src/tools/BgLauncherApp.php @@ -61,7 +61,8 @@ class BgLauncherApp extends Application { $runfile = app::with($appClass)->getRunfile(); switch ($this->action) { case self::ACTION_START: - $appClass::_manage_runfile(count($args), $args, $runfile); + $argc = count($args); + $appClass::_manage_runfile($argc, $args, $runfile); if ($runfile->warnIfLocked()) self::exit(app::EC_LOCKED); array_splice($args, 0, 0, [ PHP_BINARY, diff --git a/src/tools/SteamTrainApp.php b/src/tools/SteamTrainApp.php index b9e013a..ffd7440 100644 --- a/src/tools/SteamTrainApp.php +++ b/src/tools/SteamTrainApp.php @@ -23,6 +23,9 @@ EOT, ["-c", "--count", "args" => 1, "help" => "spécifier le nombre d'étapes", ], + ["-f", "--force-enabled", "value" => true, + "help" => "lancer la commande même si les tâches planifiées sont désactivées", + ], ["-n", "--no-install-signal-handler", "value" => false, "help" => "ne pas installer le gestionnaire de signaux", ], @@ -30,9 +33,12 @@ EOT, protected $count = 100; + protected bool $forceEnabled = false; + protected bool $installSignalHandler = true; function main() { + app::check_bgapplication_enabled($this->forceEnabled); if ($this->installSignalHandler) app::install_signal_handler(); $count = intval($this->count); msg::info("Starting train for ".words::q($count, "step#s")); diff --git a/wip_app/app/cli/Application.php b/wip_app/app/cli/Application.php index 0f3d3d5..4944637 100644 --- a/wip_app/app/cli/Application.php +++ b/wip_app/app/cli/Application.php @@ -374,4 +374,8 @@ EOT); } abstract function main(); + + static function runfile(): RunFile { + return app::with(static::class)->getRunfile(); + } }