From 083fa8e08d8fb8e44382204fe9126350081c4214 Mon Sep 17 00:00:00 2001 From: Alexandre <44178713+alexbelgium@users.noreply.github.com> Date: Thu, 5 Dec 2024 13:11:36 +0100 Subject: [PATCH] Improved pid detection --- .templates/ha_entrypoint.sh | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/.templates/ha_entrypoint.sh b/.templates/ha_entrypoint.sh index 18f47c928..eb174549c 100755 --- a/.templates/ha_entrypoint.sh +++ b/.templates/ha_entrypoint.sh @@ -59,9 +59,13 @@ if [ "$$" -eq 1 ]; then echo "Termination signal received, forwarding to subprocesses..." # Gracefully terminate open subprocesses - for pid in $(grep -l "/etc/cont-init.d" /proc/*/cmdline 2>/dev/null | grep -oP '/proc/\K[0-9]+'); do - echo "Terminating PID $pid" - kill -TERM "$pid" 2>/dev/null || true + for pid in /proc/[0-9]*/; do + pid=${pid#/proc/} + pid=${pid%/} + if [[ "$pid" -ne 1 ]]; then + echo "Terminating PID $pid" + kill -TERM "$pid" 2>/dev/null || echo "Failed to terminate PID $pid" + fi done # Wait for all child processes to terminate