Skip to content

Commit

Permalink
Daemons restarted if config page saved
Browse files Browse the repository at this point in the history
  • Loading branch information
tcharp38 committed Apr 22, 2024
1 parent f0bd402 commit 1eb15b4
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 1 deletion.
29 changes: 28 additions & 1 deletion core/ajax/Abeille.ajax.php
Original file line number Diff line number Diff line change
Expand Up @@ -435,7 +435,7 @@ function sendToCmd($topic, $payload = '') {
/* Need to start AbeilleMonitor if not already running
and restart cmd & parser.
WARNING: If cron is not running, any (re)start should be avoided. */
$conf = AbeilleTools::getParameters();
$conf = AbeilleTools::getConfig();
AbeilleTools::restartDaemons($conf, "AbeilleMonitor AbeilleParser AbeilleCmd");
}

Expand Down Expand Up @@ -805,6 +805,33 @@ function sendToCmd($topic, $payload = '') {
ajax::success(json_encode(array('status' => $status, 'error' => $error, 'config' => $configJson)));
}

// Restart Abeille's daemons
if (init('action') == 'restartDaemons') {
$status = 0;
$error = "";

$config = AbeilleTools::getConfig();
AbeilleTools::restartDaemons($config, "");

ajax::success(json_encode(array('status' => $status, 'error' => $error)));
}

// Return Abeille's running daemons
if (init('action') == 'getRunningDaemons') {
$status = 0;
$error = "";

$daemons = AbeilleTools::getRunningDaemons2();
/* 'daemons' reminder
$daemons = array(
'runningNb' => sizeof($daemons), // Nb of running daemons
'runBits' => $runBits, // 1 bit per running daemon
'daemons' => $daemons, // Detail on each daemon
); */

ajax::success(json_encode(array('status' => $status, 'error' => $error, 'daemons' => $daemons)));
}

/* WARNING: ajax::error DOES NOT trig 'error' callback on client side.
Instead 'success' callback is used. This means that
- take care of error code returned
Expand Down
1 change: 1 addition & 0 deletions docs/fr_FR/Changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
- Changelog: Migré au format markdown.
- sensor_switch.aq3: Mise-à-jour du modèle avec ajout section 'private'.
- Interne: Parser: Désactivation du support messages 8100 & 8102 (géré par 8002) pour migration mode 'raw'.
- Page de config: Les démons sont automatiquement redémarrés lors de la sauvegarde de la configuration.

## 240409-BETA-1

Expand Down
28 changes: 28 additions & 0 deletions plugin_info/configuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -1460,6 +1460,34 @@ function Abeille_postSaveConfiguration() {
}
if (errors != '')
window.alert(errors);
else {
// Restart daemons if already running
$.ajax({
type: 'POST',
url: 'plugins/Abeille/core/ajax/Abeille.ajax.php',
data: {
action: 'getRunningDaemons',
},
dataType: 'json',
global: false,
success: function (json_res) {
// console.log(json_res);
res = JSON.parse(json_res.result);
deamons = res.daemons;
running = deamons.runningNb;
if (running > 0) {
console.log(running+" daemons running => Restarting all");
$.ajax({
type: 'POST',
url: 'plugins/Abeille/core/ajax/Abeille.ajax.php',
data: {
action: 'restartDaemons',
}
});
}
}
});
}
}
});
}
Expand Down

0 comments on commit 1eb15b4

Please sign in to comment.