Skip to content

Commit 3dc755f

Browse files
committed
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 <[email protected]>
1 parent cf7d6dd commit 3dc755f

File tree

1 file changed

+10
-7
lines changed

1 file changed

+10
-7
lines changed

src/entrypoint.sh

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -121,14 +121,17 @@ while true; do
121121
next_run=$(date -r "$next_timestamp" '+%Y-%m-%d %H:%M:%S' 2>/dev/null || date '+%Y-%m-%d %H:%M:%S')
122122
echo "Next certificate renewal check will be at ${next_run}"
123123

124-
# Use wait with timeout to allow for signal interruption
124+
# Store PID of sleep process and wait for it
125125
sleep "$RENEWAL_INTERVAL" &
126-
wait $!
127-
128-
# Check if we received a signal
129-
if [ $? -gt 128 ]; then
130-
cleanup
131-
fi
126+
sleep_pid=$!
127+
wait $sleep_pid
128+
wait_status=$?
129+
130+
# Check if we received a signal (more portable check)
131+
case $wait_status in
132+
0) : ;; # Normal exit
133+
*) cleanup ;;
134+
esac
132135

133136
if ! run_certbot; then
134137
echo "Error: Certificate renewal failed. Exiting."

0 commit comments

Comments
 (0)