From c230d52bec12b74f559129963de40c33a527129d Mon Sep 17 00:00:00 2001 From: Alexandre <44178713+alexbelgium@users.noreply.github.com> Date: Thu, 5 Dec 2024 11:03:33 +0100 Subject: [PATCH] Update ha_entrypoint.sh --- .templates/ha_entrypoint.sh | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/.templates/ha_entrypoint.sh b/.templates/ha_entrypoint.sh index 62c8def13..c7d0a84ef 100755 --- a/.templates/ha_entrypoint.sh +++ b/.templates/ha_entrypoint.sh @@ -8,11 +8,10 @@ if [ "$$" -eq 1 ]; then echo "Termination signal received, forwarding to subprocesses..." # Gracefully terminate subprocesses - if command -v pkill &>/dev/null; then - pkill -P $$ - elif command -v kill &>/dev/null; then - kill -TERM -- -$$ - fi + for pid in "${pids[@]}"; do + echo "Terminating PID $pid" + kill -TERM "$pid" 2>/dev/null + done # Wait for all child processes to terminate wait @@ -23,6 +22,9 @@ fi echo "Starting..." +# Array to hold the PIDs of the subprocesses +pids=() + #################### # Starting scripts # #################### @@ -58,12 +60,15 @@ for SCRIPTS in /etc/cont-init.d/*; do sed -i "s/bashio::exit.nok/return 1/g" "$SCRIPTS" sed -i "s/bashio::exit.ok/return 0/g" "$SCRIPTS" # shellcheck source=/dev/null - (source "$SCRIPTS" || echo -e "\033[0;31mError\033[0m : $SCRIPTS exiting $? &) + source "$SCRIPTS" || echo -e "\033[0;31mError\033[0m : $SCRIPTS exiting $? & else # Support for posix only shell - ("$SCRIPTS" || echo -e "\033[0;31mError\033[0m : $SCRIPTS exiting $? &) + "$SCRIPTS" || echo -e "\033[0;31mError\033[0m : $SCRIPTS exiting $? & fi + # Track the PID of the background process + pids+=($!) + # Cleanup rm "$SCRIPTS" done