Fix ASF not reacting to Docker SIGTERM

This one is tricky, trap code works properly but bash is not reacting to it when executing a binary.

> If Bash is waiting for a command to complete and receives a signal for which a trap has been set, the trap will not be executed until the command completes.

https://www.gnu.org/software/bash/manual/html_node/Signals.html
This commit is contained in:
JustArchi 2017-10-10 03:49:24 +02:00
parent 261b5f77a0
commit 8515efd6ee

View file

@ -6,14 +6,13 @@ if [[ -z "${ASF_ARGS-}" ]]; then
ASF_ARGS=""
fi
for ARG in "$@"; do
ASF_ARGS+=" $ARG"
done
ASF_ARGS+=" $*"
# Kill underlying ASF process on shell process exit
trap "trap - SIGTERM && kill -- -$$" SIGINT SIGTERM EXIT
while [[ -f ArchiSteamFarm.dll ]]; do
dotnet ArchiSteamFarm.dll $ASF_ARGS # We will abort the script if ASF exits with an error
dotnet ArchiSteamFarm.dll $ASF_ARGS &
wait $! # This will forward dotnet error code, set -e will abort the script if it's non-zero
sleep 1
done