working background jobs, fix old pipes

This commit is contained in:
Kay Marquardt (Gnadelwartz) 2019-05-19 12:54:59 +02:00
parent a3c0d3165c
commit e7d2effc27
2 changed files with 13 additions and 9 deletions

View File

@ -12,7 +12,7 @@
# This file is public domain in the USA and all free countries. # This file is public domain in the USA and all free countries.
# Elsewhere, consider it to be WTFPLv2. (wtfpl.net/txt/copying) # Elsewhere, consider it to be WTFPLv2. (wtfpl.net/txt/copying)
# #
#### $$VERSION$$ v0.80-dev3-2-ga1a823b #### $$VERSION$$ v0.80-dev3-3-ga3c0d31
# #
# Exit Codes: # Exit Codes:
# - 0 sucess (hopefully) # - 0 sucess (hopefully)
@ -364,6 +364,9 @@ start_bot() {
[[ "${DEBUG}" = *"debug" ]] && exec &>>"DEBUG.log" [[ "${DEBUG}" = *"debug" ]] && exec &>>"DEBUG.log"
[ "${DEBUG}" != "" ] && date && echo "Start BASHBOT in Mode \"${DEBUG}\"" [ "${DEBUG}" != "" ] && date && echo "Start BASHBOT in Mode \"${DEBUG}\""
[[ "${DEBUG}" = "xdebug"* ]] && set -x [[ "${DEBUG}" = "xdebug"* ]] && set -x
#cleaup old pipes
find "${TMPDIR}" -type p -delete
while true; do while true; do
UPDATE="$(getJson "$UPD_URL$OFFSET" | "${JSONSHFILE}" -s -b -n)" UPDATE="$(getJson "$UPD_URL$OFFSET" | "${JSONSHFILE}" -s -b -n)"

View File

@ -5,7 +5,7 @@
# This file is public domain in the USA and all free countries. # This file is public domain in the USA and all free countries.
# Elsewhere, consider it to be WTFPLv2. (wtfpl.net/txt/copying) # Elsewhere, consider it to be WTFPLv2. (wtfpl.net/txt/copying)
# #
#### $$VERSION$$ v0.80-dev3-2-ga1a823b #### $$VERSION$$ v0.80-dev3-3-ga3c0d31
# source from commands.sh if you want ro use interactive or background jobs # source from commands.sh if you want ro use interactive or background jobs
@ -51,11 +51,9 @@ start_proc() {
kill_proc "$1" "$3" kill_proc "$1" "$3"
local fifo; fifo="${TMPDIR:-.}/$(procname "$1" "$3")" local fifo; fifo="${TMPDIR:-.}/$(procname "$1" "$3")"
mkfifo "${fifo}" mkfifo "${fifo}"
{ set -f nohup bash -c "{ set -f; exec 3>\"${fifo}\" &
# shellcheck disable=SC2002 cat \"${fifo}\" | $2 \"\" \"\" \"$fifo\" | \"${SCRIPT}\" outproc \"${1}\" \"${fifo}\"
cat "${fifo}" | $2 | "${SCRIPT}" outproc "${1}" "${fifo}" }" &>>"${fifo}.log" &
} &>>"${fifo}.log" &
disown -a
} }
@ -84,9 +82,12 @@ kill_back() {
# $1 chatid # $1 chatid
# $2 prefix # $2 prefix
kill_proc() { kill_proc() {
local fifo; fifo="$(procname "$1" "$2")" local fifo prid
kill -15 "$(proclist "${fifo}")" 2>/dev/null fifo="$(procname "$1" "$2")"
prid="$(proclist "${fifo}")"
fifo="${TMPDIR:-.}/${fifo}" fifo="${TMPDIR:-.}/${fifo}"
# shellcheck disable=SC2086
[ "${prid}" != "" ] && kill ${prid}
[ -s "${fifo}.log" ] || rm -f "${fifo}.log" [ -s "${fifo}.log" ] || rm -f "${fifo}.log"
[ -p "${fifo}" ] && rm -f "${fifo}"; [ -p "${fifo}" ] && rm -f "${fifo}";
} }