Skip to content

Commit

Permalink
Fix issue roleoroleo#623
Browse files Browse the repository at this point in the history
Running process detection malfunctioning due to `ps` output being truncated
  • Loading branch information
maciekn committed May 14, 2023
1 parent a3be669 commit 0777436
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 9 deletions.
8 changes: 4 additions & 4 deletions src/static/static/yi-hack/script/ftppush.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
Expand Down
8 changes: 4 additions & 4 deletions src/static/static/yi-hack/script/thumb.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/static/static/yi-hack/script/wd_rtsp.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 0777436

Please sign in to comment.