From 0fcc246760be5860071d4f40f5e16e3a63f90f12 Mon Sep 17 00:00:00 2001 From: bergware Date: Sat, 6 Jan 2024 10:47:12 +0100 Subject: [PATCH] Reduce monitor_nchan messages --- .../dynamix/include/DefaultPageLayout.php | 4 ++-- sbin/monitor_nchan | 16 +++++++++++----- 2 files changed, 13 insertions(+), 7 deletions(-) diff --git a/emhttp/plugins/dynamix/include/DefaultPageLayout.php b/emhttp/plugins/dynamix/include/DefaultPageLayout.php index a077f684d..2d5f59013 100644 --- a/emhttp/plugins/dynamix/include/DefaultPageLayout.php +++ b/emhttp/plugins/dynamix/include/DefaultPageLayout.php @@ -755,7 +755,7 @@ foreach ($pages as $page) { if ($close) echo ""; } if (count($pages)) { - $running = file_exists($nchan_pid) ? file($nchan_pid,FILE_IGNORE_NEW_LINES) : []; + $running = file_exists($nchan_pid) ? file($nchan_pid,FILE_IGNORE_NEW_LINES|FILE_SKIP_EMPTY_LINES) : []; $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 @@ -768,7 +768,7 @@ if (count($pages)) { foreach ($stop as $row) { [$script,$opt] = my_explode(':',$row); if ($opt == 'stop') { - exec("pkill -f $docroot/$script >/dev/null &"); + exec("pkill -f $docroot/$script &>/dev/null &"); array_splice($running,array_search($row,$running),1); } } diff --git a/sbin/monitor_nchan b/sbin/monitor_nchan index 2de8131be..0d6460e9a 100755 --- a/sbin/monitor_nchan +++ b/sbin/monitor_nchan @@ -8,7 +8,7 @@ nchan_id=$(basename "$0") # immediate kill command if [[ $1 == kill ]]; then - [[ -e $nchan_pid ]] || exit + [[ -s $nchan_pid ]] || exit echo "Killing nchan processes..." while IFS=$'\n' read -r running; do name="${running##*/}" @@ -28,18 +28,24 @@ if [[ $1 == kill ]]; then exit fi +start=$(date +%s) while :; do # only act when GUI registered nchan processes are running - if [[ -e $nchan_pid ]]; then + if [[ -s $nchan_pid ]]; then # get number of GUI nchan subscribers subs=$(curl --unix-socket $nginx $status 2>/dev/null|grep -Pom1 'subscribers: \K\d+') if [[ -z $subs || $subs -eq 0 ]]; then - sleep 3 + sleep 5 # steady state? subs=$(curl --unix-socket $nginx $status 2>/dev/null|grep -Pom1 'subscribers: \K\d+') if [[ -z $subs || $subs -eq 0 ]]; then - logger -t $nchan_id -- "Stop running nchan processes" - # kill GUI registered nchan processes + now=$(date +%s) + # log at 1 hour interval + if [[ $((now-start)) -ge 3600 ]]; then + logger -t $nchan_id -- "Stop running nchan processes" + start=$now + fi + # kill GUI registered nchan processes while IFS=$'\n' read -r running; do pkill -f $docroot/${running/:stop/} done < $nchan_pid