diff --git a/emhttp/plugins/dynamix/include/DefaultPageLayout.php b/emhttp/plugins/dynamix/include/DefaultPageLayout.php index c6eccfd38..6be9484a4 100644 --- a/emhttp/plugins/dynamix/include/DefaultPageLayout.php +++ b/emhttp/plugins/dynamix/include/DefaultPageLayout.php @@ -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) { - \ No newline at end of file +