From 69b1871eeaa10def04d357d5cf71127024557360 Mon Sep 17 00:00:00 2001 From: "Kay Marquardt (Gnadelwartz)" Date: Thu, 3 Jun 2021 12:03:10 +0200 Subject: [PATCH] fix Terminated message on stophook --- bashbot.rc | 6 +++--- bin/process_batch.sh | 10 +++++----- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/bashbot.rc b/bashbot.rc index 5cb3802..3bee3a0 100755 --- a/bashbot.rc +++ b/bashbot.rc @@ -5,7 +5,7 @@ # # tested on: ubuntu, opensuse, debian # -#### $$VERSION$$ v1.51-dev-10-g12157b3 +#### $$VERSION$$ v1.51-dev-22-g45efa80 # shellcheck disable=SC2009 # shellcheck disable=SC2181 # shellcheck disable=SC2250 @@ -99,9 +99,9 @@ case "$1" in 'stophook') [ "${stat}" != "hook" ] && printf "Warning, bot is not in webhook mode: %s\n" "${stat}" printf "Stopping bashbot webhook mode ... " - KILLID="$(ps -f -u "${runas}" | grep "process_batch.sh --startbot" | sed -E 's/[^0-9]+([0-9]+).*/\1/')" + KILLID="$(ps -f -u "${runas}" | grep "process_batch.sh --startbot" | sed -E 's/[^0-9]+([0-9]+).*/\1/' | tr -s "\r\n" " ")" if [ -n "${KILLID}" ]; then - $runcmd "kill $(printf "%s" "${KILLID}" | tr -s "\r\n" " " )" + $runcmd "kill ${KILLID}; wait ${KILLID} 2>/dev/null" sleep 1 fi RETVAL=$? diff --git a/bin/process_batch.sh b/bin/process_batch.sh index f313619..38b82bb 100755 --- a/bin/process_batch.sh +++ b/bin/process_batch.sh @@ -4,7 +4,7 @@ # # FILE: bin/process_batch.sh # -USAGE='process_update.sh [-h|--help] [-s|--startbot] [-w|--watch] [-n|--lines n] [file] [debug]' +USAGE='process_batch.sh [-h|--help] [-s|--startbot] [-w|--watch] [-n|--lines n] [file] [debug]' # # DESCRIPTION: processes last 10 telegram updates in file, one update per line # @@ -21,7 +21,7 @@ USAGE='process_update.sh [-h|--help] [-s|--startbot] [-w|--watch] [-n|--lines n] # AUTHOR: KayM (gnadelwartz), kay@rrr.de # CREATED: 27.02.2021 13:14 # -#### $$VERSION$$ v1.50-13-g79fc511 +#### $$VERSION$$ v1.51-dev-22-g45efa80 #=============================================================================== #### @@ -76,14 +76,14 @@ fi # ready, do stuff here ----- # kill all sub processes on exit -trap 'printf "%(%c)T: %s\n" -1 "Bot in '"${mode}"' mode stopped"; kill $(jobs -p) 2>/dev/null; send_normal_message "'"${BOTADMIN}"'" "Bot '"${BOTNAME} ${mode}"' stopped ..."' EXIT HUP QUIT +trap 'printf "%(%c)T: %s\n" -1 "Bot in '"${mode}"' mode stopped"; kill $(jobs -p) 2>/dev/null; wait $(jobs -p) 2>/dev/null; send_normal_message "'"${BOTADMIN}"'" "Bot '"${BOTNAME} ${mode}"' stopped ..."' EXIT HUP QUIT # wait after (first) update to avoid processing to many in parallel UPDWAIT="0.5" # use tail to read appended updates # shellcheck disable=SC2086,SC2248 -tail ${follow} ${lines} "${file}" |\ - while IFS="" read -r input +tail ${follow} ${lines} "${file}" 2>/dev/null |\ + while IFS="" read -r input 2>/dev/null do # read json from stdin and convert update format # replace any ID named BOTADMIN with ID of bot admin