monitor_nchan: fix incorrect PID reference in pkill / pgrep

This commit is contained in:
bergware
2025-08-13 20:53:56 +02:00
parent ce9b3aba1d
commit 4b6da9c906
+7 -3
View File
@@ -5,6 +5,7 @@ disk_load=/var/local/emhttp/diskload.ini # disk load statistics
nginx=/var/run/nginx.socket # nginx local access
status=http://localhost/pub/session?buffer_length=1 # nchan information about GUI subscribers
nchan_list=/tmp/nchan_list.tmp
pid_file=/var/run/monitor_nchan.pid
nchan_id=$(basename "$0")
nchan_subs(){
@@ -24,17 +25,19 @@ nchan_idle(){
nchan_stop() {
echo -n >$nchan_list
pid=$(cat $pid_file)
while IFS=$'\n' read -r nchan; do
[[ ${nchan##*/} == '.*' ]] && continue
echo $nchan >>$nchan_list
pkill --ns $$ -f $nchan
pkill --ns $pid -f $nchan
done <<< $(ps -eo cmd | grep -Po '/usr/local/emhttp/.*/nchan/.*')
}
nchan_start() {
[[ -e $nchan_list ]] || return
pid=$(cat $pid_file)
while IFS=$'\n' read -r nchan; do
if ! pgrep --ns $$ -f $nchan >/dev/null; then
if ! pgrep --ns $pid -f $nchan >/dev/null; then
$nchan &>/dev/null &
fi
done < $nchan_list
@@ -78,4 +81,5 @@ while :; do
fi
# check every 30 seconds
sleep 30
done &
done & echo $! >$pid_file