déplacer certains fichiers dans nur-ture
This commit is contained in:
		
							parent
							
								
									9fc0464c3d
								
							
						
					
					
						commit
						afaa816eff
					
				| @ -2,6 +2,6 @@ | ||||
| <?php | ||||
| require $_composer_autoload_path?? __DIR__.'/../vendor/autoload.php'; | ||||
| 
 | ||||
| use nulib\tools\Csv2xlsxApp; | ||||
| use nulib\cli\Csv2xlsxApp; | ||||
| 
 | ||||
| Csv2xlsxApp::run(); | ||||
|  | ||||
| @ -2,6 +2,6 @@ | ||||
| <?php | ||||
| require $_composer_autoload_path?? __DIR__.'/../vendor/autoload.php'; | ||||
| 
 | ||||
| use nulib\tools\DumpserApp; | ||||
| use nulib\cli\DumpserApp; | ||||
| 
 | ||||
| DumpserApp::run(); | ||||
|  | ||||
| @ -2,6 +2,6 @@ | ||||
| <?php | ||||
| require $_composer_autoload_path?? __DIR__.'/../vendor/autoload.php'; | ||||
| 
 | ||||
| use nulib\tools\Json2yamlApp; | ||||
| use nulib\cli\Json2yamlApp; | ||||
| 
 | ||||
| Json2yamlApp::run(); | ||||
|  | ||||
| @ -2,6 +2,6 @@ | ||||
| <?php | ||||
| require $_composer_autoload_path?? __DIR__.'/../vendor/autoload.php'; | ||||
| 
 | ||||
| use nulib\tools\NucacheApp; | ||||
| use nulib\cli\NucacheApp; | ||||
| 
 | ||||
| NucacheApp::run(); | ||||
| @ -2,6 +2,6 @@ | ||||
| <?php | ||||
| require $_composer_autoload_path?? __DIR__.'/../vendor/autoload.php'; | ||||
| 
 | ||||
| use nulib\tools\SteamTrainApp; | ||||
| use nulib\cli\StorageMysqlApp; | ||||
| 
 | ||||
| SteamTrainApp::run(); | ||||
| StorageMysqlApp::run(); | ||||
							
								
								
									
										7
									
								
								bin/storage.sqlite.php
									
									
									
									
									
										Executable file
									
								
							
							
						
						
									
										7
									
								
								bin/storage.sqlite.php
									
									
									
									
									
										Executable file
									
								
							| @ -0,0 +1,7 @@ | ||||
| #!/usr/bin/php
 | ||||
| <?php | ||||
| require $_composer_autoload_path?? __DIR__.'/../vendor/autoload.php'; | ||||
| 
 | ||||
| use nulib\cli\StorageSqliteApp; | ||||
| 
 | ||||
| StorageSqliteApp::run(); | ||||
| @ -2,6 +2,6 @@ | ||||
| <?php | ||||
| require $_composer_autoload_path?? __DIR__.'/../vendor/autoload.php'; | ||||
| 
 | ||||
| use nulib\tools\Yaml2jsonApp; | ||||
| use nulib\cli\Yaml2jsonApp; | ||||
| 
 | ||||
| Yaml2jsonApp::run(); | ||||
|  | ||||
| @ -79,9 +79,12 @@ | ||||
| 	}, | ||||
| 	"bin": [ | ||||
| 		"bin/dumpser.php", | ||||
| 		"bin/nucache.php", | ||||
| 		"bin/csv2xlsx.php", | ||||
| 		"bin/json2yml.php", | ||||
| 		"bin/yml2json.php", | ||||
| 		"bin/storage.sqlite.php", | ||||
| 		"bin/storage.mysql.php", | ||||
| 		"nur_bin/compctl.php", | ||||
| 		"nur_bin/compdep.php", | ||||
| 		"nur_bin/datectl.php", | ||||
| @ -89,9 +92,7 @@ | ||||
| 		"nur_bin/cachectl.php", | ||||
| 		"nur_bin/ldap-delete.php", | ||||
| 		"nur_bin/ldap-get-infos.php", | ||||
| 		"nur_bin/ldap-search.php", | ||||
| 		"nur_bin/storage.sqlite.php", | ||||
| 		"nur_bin/storage.mysql.php" | ||||
| 		"nur_bin/ldap-search.php" | ||||
| 	], | ||||
| 	"authors": [ | ||||
| 		{ | ||||
|  | ||||
							
								
								
									
										124
									
								
								src/cli/BgLauncherApp.php
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										124
									
								
								src/cli/BgLauncherApp.php
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,124 @@ | ||||
| <?php | ||||
| namespace nulib\cli; | ||||
| 
 | ||||
| use nulib\app; | ||||
| use nulib\app\cli\Application; | ||||
| use nulib\app\RunFile; | ||||
| use nulib\ExitError; | ||||
| use nulib\ext\yaml; | ||||
| use nulib\os\path; | ||||
| use nulib\os\proc\Cmd; | ||||
| use nulib\os\sh; | ||||
| use nulib\output\msg; | ||||
| 
 | ||||
| class BgLauncherApp extends Application { | ||||
|   const ACTION_INFOS = 0, ACTION_START = 1, ACTION_STOP = 2; | ||||
|   const ARGS = [ | ||||
|     "purpose" => "lancer un script en tâche de fond", | ||||
|     "usage" => "ApplicationClass args...", | ||||
| 
 | ||||
|     "sections" => [ | ||||
|       parent::VERBOSITY_SECTION, | ||||
|     ], | ||||
| 
 | ||||
|     ["-i", "--infos", "name" => "action", "value" => self::ACTION_INFOS, | ||||
|       "help" => "Afficher des informations sur la tâche", | ||||
|     ], | ||||
|     ["-s", "--start", "name" => "action", "value" => self::ACTION_START, | ||||
|       "help" => "Démarrer la tâche", | ||||
|     ], | ||||
|     ["-k", "--stop", "name" => "action", "value" => self::ACTION_STOP, | ||||
|       "help" => "Arrêter la tâche", | ||||
|     ], | ||||
|   ]; | ||||
| 
 | ||||
|   protected int $action = self::ACTION_START; | ||||
| 
 | ||||
|   protected ?array $args = null; | ||||
| 
 | ||||
|   static function show_infos(RunFile $runfile, ?int $level=null): void { | ||||
|     msg::print($runfile->getDesc(), $level); | ||||
|     msg::print(yaml::with(["data" => $runfile->read()]), ($level ?? 0) - 1); | ||||
|   } | ||||
| 
 | ||||
|   function main() { | ||||
|     $args = $this->args; | ||||
| 
 | ||||
|     $appClass = $args[0] ?? null; | ||||
|     if ($appClass === null) { | ||||
|       self::die("Vous devez spécifier la classe de l'application"); | ||||
|     } | ||||
|     $appClass = $args[0] = str_replace("/", "\\", $appClass); | ||||
|     if (!class_exists($appClass)) { | ||||
|       self::die("$appClass: classe non trouvée"); | ||||
|     } | ||||
| 
 | ||||
|     $useRunfile = constant("$appClass::USE_RUNFILE"); | ||||
|     if (!$useRunfile) { | ||||
|       self::die("Cette application ne supporte le lancement en tâche de fond"); | ||||
|     } | ||||
| 
 | ||||
|     $runfile = app::with($appClass)->getRunfile(); | ||||
|     switch ($this->action) { | ||||
|     case self::ACTION_START: | ||||
|       $argc = count($args); | ||||
|       $appClass::_manage_runfile($argc, $args, $runfile); | ||||
|       if ($runfile->warnIfLocked()) self::exit(app::EC_LOCKED); | ||||
|       array_splice($args, 0, 0, [ | ||||
|         PHP_BINARY, | ||||
|         path::abspath(NULIB_APP_app_launcher), | ||||
|       ]); | ||||
|       app::params_putenv(); | ||||
|       self::_start($args, $runfile); | ||||
|       break; | ||||
|     case self::ACTION_STOP: | ||||
|       self::_stop($runfile); | ||||
|       self::show_infos($runfile, -1); | ||||
|       break; | ||||
|     case self::ACTION_INFOS: | ||||
|       self::show_infos($runfile); | ||||
|       break; | ||||
|     } | ||||
|   } | ||||
| 
 | ||||
|   public static function _start(array $args, Runfile $runfile): void { | ||||
|     $pid = pcntl_fork(); | ||||
|     if ($pid == -1) { | ||||
|       # parent, impossible de forker
 | ||||
|       throw new ExitError(app::EC_FORK_PARENT, "Unable to fork"); | ||||
|     } elseif (!$pid) { | ||||
|       # child, fork ok
 | ||||
|       $runfile->wfPrepare($pid); | ||||
|       $outfile = $runfile->getOutfile() ?? "/tmp/NULIB_APP_app_console.out"; | ||||
|       $exitcode = app::EC_FORK_CHILD; | ||||
|       try { | ||||
|         # rediriger STDIN, STDOUT et STDERR
 | ||||
|         fclose(fopen($outfile, "wb")); // vider le fichier
 | ||||
|         fclose(STDIN); $in = fopen("/dev/null", "rb"); | ||||
|         fclose(STDOUT); $out = fopen($outfile, "ab"); | ||||
|         fclose(STDERR); $err = fopen($outfile, "ab"); | ||||
|         # puis lancer la commande
 | ||||
|         $cmd = new Cmd($args); | ||||
|         $cmd->addSource("/g/init.env"); | ||||
|         $cmd->addRedir("both", $outfile, 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; | ||||
|     } | ||||
|   } | ||||
| } | ||||
| @ -1,5 +1,5 @@ | ||||
| <?php | ||||
| namespace nulib\tools; | ||||
| namespace nulib\cli; | ||||
| 
 | ||||
| use nulib\app\cli\Application; | ||||
| use nulib\ext\tab\SsBuilder; | ||||
| @ -1,5 +1,5 @@ | ||||
| <?php | ||||
| namespace nulib\tools; | ||||
| namespace nulib\cli; | ||||
| 
 | ||||
| use nulib\app\cli\Application; | ||||
| use nulib\ext\yaml; | ||||
| @ -1,5 +1,5 @@ | ||||
| <?php | ||||
| namespace nulib\tools; | ||||
| namespace nulib\cli; | ||||
| 
 | ||||
| use nulib\app\cli\Application; | ||||
| use nulib\ext\json; | ||||
| @ -1,10 +1,10 @@ | ||||
| <?php | ||||
| namespace nulib\tools; | ||||
| namespace nulib\cli; | ||||
| 
 | ||||
| use Exception; | ||||
| use nulib\app\cli\Application; | ||||
| use nulib\ext\yaml; | ||||
| use nulib\cache\CacheFile; | ||||
| use nulib\ext\yaml; | ||||
| use nulib\os\path; | ||||
| use nulib\output\msg; | ||||
| 
 | ||||
							
								
								
									
										53
									
								
								src/cli/SteamTrainApp.php
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										53
									
								
								src/cli/SteamTrainApp.php
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,53 @@ | ||||
| <?php | ||||
| namespace nulib\cli; | ||||
| 
 | ||||
| use nulib\app; | ||||
| use nulib\app\cli\Application; | ||||
| use nulib\output\msg; | ||||
| use nulib\php\time\DateTime; | ||||
| use nulib\text\words; | ||||
| 
 | ||||
| class SteamTrainApp extends Application { | ||||
|   const PROJDIR = __DIR__.'/../..'; | ||||
|   const TITLE = "Train à vapeur"; | ||||
|   const USE_LOGFILE = true; | ||||
|   const USE_RUNFILE = true; | ||||
|   const USE_RUNLOCK = true; | ||||
| 
 | ||||
|   const ARGS = [ | ||||
|     "purpose" => self::TITLE, | ||||
|     "description" => <<<EOT | ||||
| Cette application peut être utilisée pour tester le lancement des tâches de fond | ||||
| 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", | ||||
|     ], | ||||
|   ]; | ||||
| 
 | ||||
|   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")); | ||||
|     app::action("Running train...", $count); | ||||
|     for ($i = 1; $i <= $count; $i++) { | ||||
|       msg::print("Tchou-tchou! x $i"); | ||||
|       app::step(); | ||||
|       sleep(1); | ||||
|     } | ||||
|     msg::info("Stopping train at ".new DateTime()); | ||||
|   } | ||||
| } | ||||
							
								
								
									
										11
									
								
								nur_bin/storage.mysql.php → src/cli/StorageMysqlApp.php
									
									
									
									
									
										
										
										Executable file → Normal file
									
								
							
							
						
						
									
										11
									
								
								nur_bin/storage.mysql.php → src/cli/StorageMysqlApp.php
									
									
									
									
									
										
										
										Executable file → Normal file
									
								
							| @ -1,16 +1,15 @@ | ||||
| #!/usr/bin/php
 | ||||
| <?php | ||||
| require $_composer_autoload_path?? __DIR__.'/../vendor/autoload.php'; | ||||
| namespace nulib\cli; | ||||
| 
 | ||||
| use nulib\app\cli\Application; | ||||
| use nulib\db\Capacitor; | ||||
| use nulib\db\CapacitorChannel; | ||||
| use nulib\db\mysql\MysqlStorage; | ||||
| use nulib\ext\yaml; | ||||
| use nulib\file\Stream; | ||||
| use nur\cli\Application; | ||||
| use nur\config; | ||||
| use nur\yaml; | ||||
| 
 | ||||
| Application::run(new class extends Application { | ||||
| class StorageMysqlApp extends Application { | ||||
|   const ACTION_QUERY = 0, ACTION_SQL = 1; | ||||
| 
 | ||||
|   const ARGS = [ | ||||
| @ -120,4 +119,4 @@ Application::run(new class extends Application { | ||||
|       break; | ||||
|     } | ||||
|   } | ||||
| }); | ||||
| } | ||||
							
								
								
									
										13
									
								
								nur_bin/storage.sqlite.php → src/cli/StorageSqliteApp.php
									
									
									
									
									
										
										
										Executable file → Normal file
									
								
							
							
						
						
									
										13
									
								
								nur_bin/storage.sqlite.php → src/cli/StorageSqliteApp.php
									
									
									
									
									
										
										
										Executable file → Normal file
									
								
							| @ -1,16 +1,15 @@ | ||||
| #!/usr/bin/php
 | ||||
| <?php | ||||
| require $_composer_autoload_path?? __DIR__.'/../vendor/autoload.php'; | ||||
| namespace nulib\cli; | ||||
| 
 | ||||
| use nulib\app\cli\Application; | ||||
| use nulib\db\Capacitor; | ||||
| use nulib\db\CapacitorChannel; | ||||
| use nulib\db\sqlite\SqliteStorage; | ||||
| use nulib\ext\yaml; | ||||
| use nulib\file\Stream; | ||||
| use nur\cli\Application; | ||||
| use nur\msg; | ||||
| use nur\yaml; | ||||
| use nulib\output\msg; | ||||
| 
 | ||||
| Application::run(new class extends Application { | ||||
| class StorageSqliteApp extends Application { | ||||
|   const ACTION_QUERY = 0, ACTION_SQL = 1; | ||||
| 
 | ||||
|   const ARGS = [ | ||||
| @ -139,4 +138,4 @@ Application::run(new class extends Application { | ||||
|       break; | ||||
|     } | ||||
|   } | ||||
| }); | ||||
| } | ||||
| @ -1,5 +1,5 @@ | ||||
| <?php | ||||
| namespace nulib\tools; | ||||
| namespace nulib\cli; | ||||
| 
 | ||||
| use nulib\app\cli\Application; | ||||
| use nulib\ext\json; | ||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user