Skip to content

Commit

Permalink
Refactor entrypoint.sh to improve signal handling during sleep
Browse files Browse the repository at this point in the history
- 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 <[email protected]>
  • Loading branch information
jaydrogers committed Jan 8, 2025
1 parent cf7d6dd commit 3dc755f
Showing 1 changed file with 10 additions and 7 deletions.
17 changes: 10 additions & 7 deletions src/entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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."
Expand Down

0 comments on commit 3dc755f

Please sign in to comment.