From 0777436a27ca9c285b37a55d4292dac8c496ac4e Mon Sep 17 00:00:00 2001 From: MaciekN Date: Sun, 14 May 2023 09:37:03 +0200 Subject: [PATCH] Fix issue #623 Running process detection malfunctioning due to `ps` output being truncated --- src/static/static/yi-hack/script/ftppush.sh | 8 ++++---- src/static/static/yi-hack/script/thumb.sh | 8 ++++---- src/static/static/yi-hack/script/wd_rtsp.sh | 2 +- 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/src/static/static/yi-hack/script/ftppush.sh b/src/static/static/yi-hack/script/ftppush.sh index ead2f1b..528046b 100755 --- a/src/static/static/yi-hack/script/ftppush.sh +++ b/src/static/static/yi-hack/script/ftppush.sh @@ -281,7 +281,7 @@ serviceMain () trap "" SIGHUP # if [ "${1}" = "cron" ]; then - RUNNING=$(ps | grep $SCRIPT_FULLFN | grep -v grep | grep /bin/sh | awk 'END { print NR }') + RUNNING=$(ps ww | grep $SCRIPT_FULLFN | grep -v grep | grep /bin/sh | awk 'END { print NR }') if [ $RUNNING -gt 1 ]; then logAdd "[INFO] === SERVICE ALREADY RUNNING ===" exit 0 @@ -290,7 +290,7 @@ if [ "${1}" = "cron" ]; then logAdd "[INFO] === SERVICE STOPPED ===" exit 0 elif [ "${1}" = "start" ]; then - RUNNING=$(ps | grep $SCRIPT_FULLFN | grep -v grep | grep /bin/sh | awk 'END { print NR }') + RUNNING=$(ps ww | grep $SCRIPT_FULLFN | grep -v grep | grep /bin/sh | awk 'END { print NR }') if [ $RUNNING -gt 1 ]; then logAdd "[INFO] === SERVICE ALREADY RUNNING ===" exit 0 @@ -301,13 +301,13 @@ elif [ "${1}" = "start" ]; then wait exit 0 elif [ "${1}" = "stop" ]; then - ps w | grep -v grep | grep "ash ${0}" | sed 's/ \+/|/g' | sed 's/^|//' | cut -d '|' -f 1 | grep -v "^$$" | while read pidhandle; do + ps ww | grep -v grep | grep "ash ${0}" | sed 's/ \+/|/g' | sed 's/^|//' | cut -d '|' -f 1 | grep -v "^$$" | while read pidhandle; do echo "[INFO] Terminating old service instance [${pidhandle}] ..." kill -9 "${pidhandle}" done # # Check if parts of the service are still running. - if [ "$(ps w | grep -v grep | grep "ash ${0}" | sed 's/ \+/|/g' | sed 's/^|//' | cut -d '|' -f 1 | grep -v "^$$" | grep -c "^")" -gt 1 ]; then + if [ "$(ps ww | grep -v grep | grep "ash ${0}" | sed 's/ \+/|/g' | sed 's/^|//' | cut -d '|' -f 1 | grep -v "^$$" | grep -c "^")" -gt 1 ]; then logAdd "[ERROR] === SERVICE FAILED TO STOP ===" exit 99 fi diff --git a/src/static/static/yi-hack/script/thumb.sh b/src/static/static/yi-hack/script/thumb.sh index c1d0779..0775547 100755 --- a/src/static/static/yi-hack/script/thumb.sh +++ b/src/static/static/yi-hack/script/thumb.sh @@ -157,7 +157,7 @@ serviceMain () trap "" SIGHUP # if [ "${1}" = "cron" ]; then - RUNNING=$(ps | grep $SCRIPT_FULLFN | grep -v grep | grep /bin/sh | awk 'END { print NR }') + RUNNING=$(ps ww| grep $SCRIPT_FULLFN | grep -v grep | grep /bin/sh | awk 'END { print NR }') if [ $RUNNING -gt 1 ]; then logAdd "[INFO] === SERVICE ALREADY RUNNING ===" exit 0 @@ -166,7 +166,7 @@ if [ "${1}" = "cron" ]; then logAdd "[INFO] === SERVICE STOPPED ===" exit 0 elif [ "${1}" = "start" ]; then - RUNNING=$(ps | grep $SCRIPT_FULLFN | grep -v grep | grep /bin/sh | awk 'END { print NR }') + RUNNING=$(ps ww| grep $SCRIPT_FULLFN | grep -v grep | grep /bin/sh | awk 'END { print NR }') if [ $RUNNING -gt 1 ]; then logAdd "[INFO] === SERVICE ALREADY RUNNING ===" exit 0 @@ -177,13 +177,13 @@ elif [ "${1}" = "start" ]; then wait exit 0 elif [ "${1}" = "stop" ]; then - ps w | grep -v grep | grep "ash ${0}" | sed 's/ \+/|/g' | sed 's/^|//' | cut -d '|' -f 1 | grep -v "^$$" | while read pidhandle; do + ps ww | grep -v grep | grep "ash ${0}" | sed 's/ \+/|/g' | sed 's/^|//' | cut -d '|' -f 1 | grep -v "^$$" | while read pidhandle; do echo "[INFO] Terminating old service instance [${pidhandle}] ..." kill -9 "${pidhandle}" done # # Check if parts of the service are still running. - if [ "$(ps w | grep -v grep | grep "ash ${0}" | sed 's/ \+/|/g' | sed 's/^|//' | cut -d '|' -f 1 | grep -v "^$$" | grep -c "^")" -gt 1 ]; then + if [ "$(ps ww | grep -v grep | grep "ash ${0}" | sed 's/ \+/|/g' | sed 's/^|//' | cut -d '|' -f 1 | grep -v "^$$" | grep -c "^")" -gt 1 ]; then logAdd "[ERROR] === SERVICE FAILED TO STOP ===" exit 99 fi diff --git a/src/static/static/yi-hack/script/wd_rtsp.sh b/src/static/static/yi-hack/script/wd_rtsp.sh index 97c8fd8..dded05e 100755 --- a/src/static/static/yi-hack/script/wd_rtsp.sh +++ b/src/static/static/yi-hack/script/wd_rtsp.sh @@ -109,7 +109,7 @@ check_rtsp_alt() check_rmm() { # echo "$(date +'%Y-%m-%d %H:%M:%S') - Checking rmm process..." >> $LOG_FILE - PS=`ps | grep rmm | grep -v grep | grep -c ^` + PS=`ps ww| grep rmm | grep -v grep | grep -c ^` if [ $PS -eq 0 ]; then reboot