diff --git a/configWatch.php b/configWatch.php new file mode 100644 index 0000000..e1e4b72 --- /dev/null +++ b/configWatch.php @@ -0,0 +1,50 @@ + diff --git a/moha.php b/moha.php index 9a6b940..3bde973 100644 --- a/moha.php +++ b/moha.php @@ -62,6 +62,8 @@ if ($testMode) require "/etc/moha/liste_telephones.php"; if (!init()) exit(1); +// (re)démarre le démon de présence +system("systemctl restart presenceD"); // gettext bindtextdomain("moha", "./locale"); @@ -150,7 +152,7 @@ function listHooks($dir, &$hookList) function endMoha() { - global $testMode, $devices, $topics, $events, $nSubscribed ,$client, $logFh, $connected, $dataPath; + global $testMode, $devices, $topics, $events, $nSubscribed ,$client, $logFh, $connected, $dataPath, $cwfd, $watch_descriptor; $x = 0; logger(WARNING, _("moha is ending"), __FILE__ . ":" . __LINE__); @@ -167,6 +169,10 @@ function endMoha() logger(ERROR, _("Can not store events db" ), __FILE__ . ":" . __LINE__); } if($testMode) file_put_contents($dataPath . "moha.devices", var_export($devices, true)); + // stop la surveillance + inotify_rm_watch($cwfd, $watch_descriptor); + // Destruction de l'instance inotify + fclose($cwfd); if ($connected) { $mid = $client->unsubscribe("#"); @@ -217,7 +223,7 @@ require "db_functions.php"; require "config/liste_telephones.php"; require "presence.php"; require "apiserver/apiserver.php"; - +require "configWatch.php"; logger(DEBUG, _("Loading stored events datas from ") . $dataPath . "events.db", __FILE__ . ":" . __LINE__); if (file_exists($dataPath . "events.db")) @@ -331,6 +337,9 @@ logger(INFO, _("Starting loop"), __FILE__ . ":" . __LINE__, false); $oneshot = false; logger(ALERT, _("Moha started"), __FILE__ . ":" . __LINE__); +// démarre la surveillance du dossier de configuration : /etc/moha +configWatchInit(); + while (true) { $client->loop(); // mqtt server loop() @@ -372,6 +381,27 @@ while (true) checkEvents(); checkTopicsAvailability(); if ($apiServerIsActive) apiServer($read); + + // surveillance du dossier de configuration + if ($cwfd !== false) + { + $input = inotify_read($cwfd); // Does no block, and return false if no events are pending + if ($input !== false) + { + foreach ($input as $event) + { + logger(DEBUG, _("configWatch : inclus ") . $configDir . "/" . $event["name"], __FILE__ . ":" . __LINE__); + if (pathinfo($event["name"], PATHINFO_EXTENSION) == "php") + { + include $configDir . "/" . $event["name"]; + }else + { + logger(DEBUG, _("configWatch : mauvaise extension, n'inclus pas ") . $configDir . "/" . $event["name"], __FILE__ . ":" . __LINE__); + } + + } + } + } //presence(); }