Fix: Prevent nchan scripts from spawning

Also, if a script is listed as it is supposed to be running and it isn't, then restart it
This commit is contained in:
Squidly271
2025-08-09 23:15:46 -04:00
committed by GitHub
parent 18fdb23d26
commit ec795ac882

View File

@@ -64,12 +64,15 @@ if (count($pages)) {
$start = array_diff($nchan, $running); // returns any new scripts to be started
$stop = array_diff($running, $nchan); // returns any old scripts to be stopped
$running = array_merge($start, $running); // update list of current running nchan scripts
// start nchan scripts which are new
foreach ($start as $row) {
// start nchan scripts which are new or have been terminated without updating nchan.pid
foreach ($running as $row) {
$script = explode(':', $row)[0];
exec("$docroot/$script &>/dev/null &");
exec("pgrep --ns $$ -f ".escapeshellarg("$docroot/$script"), $output, $retval);
if ($retval==1) {
exec(escapeshellarg("$docroot/$script")." &>/dev/null &");
}
}
// stop nchan scripts with the :stop option
// stop nchan scripts with the :stop option
foreach ($stop as $row) {
[$script, $opt] = my_explode(':', $row);
if ($opt == 'stop') {
@@ -78,7 +81,7 @@ if (count($pages)) {
}
}
if (count($running)) {
file_put_contents($nchan_pid, implode("\n", $running) . "\n");
file_put_contents_atomic($nchan_pid, implode("\n", $running) . "\n");
} else {
@unlink($nchan_pid);
}
@@ -163,4 +166,4 @@ foreach ($pages as $page) {
<?php include "$docroot/webGui/include/DefaultPageLayout/ToastSetup.php"; ?>
</body>
</html>
</html>