From ad7e74e724cb37bb62b7adf3015f3f7e14848b9f Mon Sep 17 00:00:00 2001 From: Alexandre <44178713+alexbelgium@users.noreply.github.com> Date: Mon, 2 Dec 2024 20:16:16 +0100 Subject: [PATCH] Sigterm handling --- .templates/ha_entrypoint.sh | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/.templates/ha_entrypoint.sh b/.templates/ha_entrypoint.sh index 01a520bfe..d266388e7 100755 --- a/.templates/ha_entrypoint.sh +++ b/.templates/ha_entrypoint.sh @@ -2,6 +2,20 @@ # shellcheck shell=bash echo "Starting..." +################## +# Handle sigterm # +################## + +cleanup() { + echo "Caught SIGTERM, cleaning up..." + # Sends SIGTERM to all child processes + pkill -TERM -P $$ || true + wait + exit 0 +} + +trap cleanup SIGTERM || true + #################### # Starting scripts # #################### @@ -40,7 +54,7 @@ for SCRIPTS in /etc/cont-init.d/*; do 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 # Cleanup