From cbde841bae8dd6cf52b5a9d31ad2f66ee4208c5d Mon Sep 17 00:00:00 2001 From: "Kay Marquardt (Gnadelwartz)" Date: Thu, 18 Mar 2021 12:35:14 +0100 Subject: [PATCH] bashbot.rc: factor out status, warn if wrong status --- bashbot.rc | 50 ++++++++++++++++++++++++++++++++++++-------------- 1 file changed, 36 insertions(+), 14 deletions(-) diff --git a/bashbot.rc b/bashbot.rc index 9334286..e4cc717 100755 --- a/bashbot.rc +++ b/bashbot.rc @@ -5,7 +5,7 @@ # # tested on: ubuntu, opensuse, debian # -#### $$VERSION$$ v1.5-0-g8adca9b +#### $$VERSION$$ v1.51-dev-5-gf1ea494 # shellcheck disable=SC2009 # shellcheck disable=SC2181 # shellcheck disable=SC2250 @@ -49,14 +49,34 @@ mode="" # END Configuration ####################### -[ "${name}" = "" ] && name="${runas}" +[ -z "${name}" ] && name="unknown" + +# check for bot status +ps -f -u "${runas}" | grep "${name}" | grep -qF "bashbot.sh startbot" +if [ "$?" = "0" ]; then + # printf "bashbot (%s) is running in poll mode\n" "${name}" + stat="poll" +else + ps -f -u "${runas}" | grep "${name}" | grep -qF "process_batch.sh --startbot" + if [ "$?" = "0" ]; then + #printf "bashbot (%s) is running in webhook mode\n" "${name}" + stat="hook" + elif [ "${name}" != "unknown" ]; then + #printf "bashbot (%s) is stopped\n" "${name}" + stat="stop" + else + stat="unknown" + fi +fi case "$1" in 'start') + [ "${stat}" != "stop" ] && printf "Warning, bot is not stopped: %s\n" "${stat}" $runcmd "$bashbot start $mode" # >/dev/null 2>&1 >${bashbotdir}/logs/WEBHOOK.log &" # >/dev/null 2>&1