mirror of
https://github.com/octoleo/telegram-bot-bash.git
synced 2025-03-19 15:42:22 +00:00
bin: process_batch: fix options bashbot.rc: support webhook
This commit is contained in:
parent
24158142f9
commit
7b8e391479
41
bashbot.rc
41
bashbot.rc
@ -5,7 +5,7 @@
|
||||
#
|
||||
# tested on: ubuntu, opensuse, debian
|
||||
#
|
||||
#### $$VERSION$$ v1.45-dev-59-ga9ac7ea
|
||||
#### $$VERSION$$ v1.45-dev-60-g2415814
|
||||
# shellcheck disable=SC2009
|
||||
# shellcheck disable=SC2181
|
||||
|
||||
@ -34,11 +34,14 @@ runas="nobody"
|
||||
# runcmd="runuser ${runas} -s /bin/bash -c " # runasuser with *runuser*
|
||||
|
||||
# edit the values of the following lines to fit your config:
|
||||
# your bot installation dir
|
||||
bashbotdir="/usr/local/telegram-bot-bash"
|
||||
bashbot="cd ${bashbotdir}; ${bashbotdir}/bashbot.sh"
|
||||
# your bot name as given to botfather, e.g. mysomething_bot
|
||||
name=""
|
||||
# your bot installation dir
|
||||
bashbotdir="/usr/local/telegram-bot-bash"
|
||||
databotdir="${bashbotdir}/data-bot-bash"
|
||||
# programs to run
|
||||
bashbot="cd ${bashbotdir}; ${bashbotdir}/bashbot.sh"
|
||||
webhook="cd ${bashbotdir}; ${bashbotdir}/bin/process_batch.sh --start --watch ${databotdir}/webhook-fifo-${name}"
|
||||
# set additionl parameter, e.g. debug
|
||||
mode=""
|
||||
|
||||
@ -53,25 +56,45 @@ case "$1" in
|
||||
$runcmd "$bashbot start $mode" # >/dev/null 2>&1 </dev/null
|
||||
RETVAL=$?
|
||||
;;
|
||||
'starthook')
|
||||
# shellcheck disable=SC2250
|
||||
$runcmd "$webhook $mode" # >/dev/null 2>&1 </dev/null
|
||||
RETVAL=$?
|
||||
;;
|
||||
'stop')
|
||||
# shellcheck disable=SC2250
|
||||
$runcmd "$bashbot stop $mode"
|
||||
RETVAL=$?
|
||||
;;
|
||||
'stophook')
|
||||
# shellcheck disable=SC2250
|
||||
pkill -u "${runas}" "process_batch.sh"
|
||||
RETVAL=$?
|
||||
;;
|
||||
'status')
|
||||
ps -f -u "${runas}" | grep "${name}" | grep -qF "bashbot.sh startbot"
|
||||
ps -f -u "${runas}" | grep "${name}" | grep -qF "process_batch.sh --start --watch"
|
||||
if [ "$?" = "0" ]; then
|
||||
printf "bashbot (%s) is running\n" "${name}"
|
||||
printf "bashbot (%s) is running in poll mode\n" "${name}"
|
||||
RETVAL=0
|
||||
else
|
||||
printf "bashbot (%s) is stopped\n" "${name}"
|
||||
RETVAL=1
|
||||
ps -f -u "${runas}" | grep "${name}" | grep -qF ""
|
||||
if [ "$?" = "0" ]; then
|
||||
printf "bashbot (%s) is running in webhook mode\n" "${name}"
|
||||
RETVAL=0
|
||||
else
|
||||
printf "bashbot (%s) is stopped\n" "${name}"
|
||||
RETVAL=1
|
||||
fi
|
||||
fi
|
||||
;;
|
||||
'restart'|'reload')
|
||||
$0 stop; $0 start
|
||||
RETVAL=$?
|
||||
;;
|
||||
'restarthook'|'reloadhook')
|
||||
$0 stophook; $0 starthook
|
||||
RETVAL=$?
|
||||
;;
|
||||
'restartback')
|
||||
$0 suspendback; $0 resumeback
|
||||
RETVAL=$?
|
||||
@ -87,7 +110,7 @@ case "$1" in
|
||||
fi
|
||||
;;
|
||||
*)
|
||||
printf "%s\n" "Usage: $0 { start | stop | restart | reload | restartback | suspendback | resumeback | killback }"
|
||||
printf "%s\n" "Usage: $0 { start | stop | starthook | restart | reload | restartback | suspendback | resumeback | killback }"
|
||||
RETVAL=1
|
||||
;;
|
||||
esac
|
||||
|
@ -29,12 +29,16 @@ USAGE='process_update.sh [-h|--help] [-s|--startbot] [-w|--watch] [-n|--lines n]
|
||||
COMMAND="process_multi_updates"
|
||||
lines="-n 10"
|
||||
|
||||
case "$1" in
|
||||
opt=0
|
||||
while [[ "$opt" -lt 5 && "$1" == "-"* ]]
|
||||
do
|
||||
(( opt++ ))
|
||||
case "$1" in
|
||||
"-s"|"--startbot")
|
||||
startbot="yes"
|
||||
shift
|
||||
;;
|
||||
"-f"|"--follow")
|
||||
"-w"|"--watch")
|
||||
follow="-f"
|
||||
shift
|
||||
;;
|
||||
@ -42,7 +46,8 @@ case "$1" in
|
||||
lines="-n $2"
|
||||
shift 2
|
||||
;;
|
||||
esac
|
||||
esac
|
||||
done
|
||||
|
||||
# set bashbot environment
|
||||
source "${0%/*}/bashbot_env.inc.sh" "debug" # debug
|
||||
@ -55,8 +60,9 @@ file="${WEBHOOK}"
|
||||
# start bot
|
||||
if [ -n "${startbot}" ]; then
|
||||
# warn when starting bot without pipe
|
||||
[ -p "${WEBHOOK}" ] || printf "%b\n" "${ORANGE}Warning${NC}: File is not a pipe:${GREY} ${file##*/}${NC}"
|
||||
[ -p "${file}" ] || printf "%b\n" "${ORANGE}Warning${NC}: File is not a pipe:${GREY} ${file##*/}${NC}"
|
||||
start_bot "$2"
|
||||
printf "${GREEN}Bot start actions done, start reading updates ....${NN}"
|
||||
fi
|
||||
# check file exist
|
||||
if [[ ! -r "${file}" || -d "${file}" ]]; then
|
||||
@ -68,7 +74,7 @@ fi
|
||||
# ready, do stuff here -----
|
||||
|
||||
# kill all sub processes on exit
|
||||
trap 'kill $(jobs -p) 2>/dev/null' EXIT HUP QUIT
|
||||
trap 'kill $(jobs -p) 2>/dev/null; printf "Bot in batch mode killed!\n"' EXIT HUP QUIT
|
||||
|
||||
# use tail to read appended updates
|
||||
# shellcheck disable=SC2086,SC2248
|
||||
|
Loading…
x
Reference in New Issue
Block a user