From 3dc755f302f5a454bb434d2f33c3ff0bca80d996 Mon Sep 17 00:00:00 2001 From: Jay Rogers Date: Wed, 8 Jan 2025 16:30:53 -0600 Subject: [PATCH] Refactor entrypoint.sh to improve signal handling during sleep - Store the PID of the sleep process to allow for more reliable signal interruption. - Use a case statement for checking the exit status of the wait command, enhancing portability and clarity. - Maintain existing functionality while improving code readability and robustness. Co-authored-by: Jay Rogers --- src/entrypoint.sh | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/src/entrypoint.sh b/src/entrypoint.sh index 6a081b4..20dca2d 100644 --- a/src/entrypoint.sh +++ b/src/entrypoint.sh @@ -121,14 +121,17 @@ while true; do next_run=$(date -r "$next_timestamp" '+%Y-%m-%d %H:%M:%S' 2>/dev/null || date '+%Y-%m-%d %H:%M:%S') echo "Next certificate renewal check will be at ${next_run}" - # Use wait with timeout to allow for signal interruption + # Store PID of sleep process and wait for it sleep "$RENEWAL_INTERVAL" & - wait $! - - # Check if we received a signal - if [ $? -gt 128 ]; then - cleanup - fi + sleep_pid=$! + wait $sleep_pid + wait_status=$? + + # Check if we received a signal (more portable check) + case $wait_status in + 0) : ;; # Normal exit + *) cleanup ;; + esac if ! run_certbot; then echo "Error: Certificate renewal failed. Exiting."