Embed SIGTERM

This commit is contained in:
Alexandre
2024-12-04 09:50:08 +01:00
committed by GitHub
parent 77fa4c2c9d
commit 560ea8ee77

View File

@@ -1,5 +1,28 @@
#!/command/with-contenv bashio
# shellcheck shell=bash
# Only trap SIGTERM if the script's PID is 1
if [ "$$" -eq 1 ]; then
echo "PID is 1, trapping SIGTERM..."
set -m
terminate() {
echo "Termination signal received, forwarding to subprocesses..."
# Check for available commands to terminate subprocesses
if command -v pkill &>/dev/null; then
pkill -P $$
elif command -v kill &>/dev/null; then
kill -TERM -- -$$
fi
# Wait for all child processes to terminate
wait
echo "All subprocesses terminated. Exiting."
exit 0
}
trap terminate SIGTERM
fi
echo "Starting..."
####################