@@ -26,42 +26,32 @@ trap cleanup EXIT
2626# Run a nginx container for ${domains[0]}.
2727run_nginx_container --hosts " ${domains[0]} "
2828
29- # Wait for a symlink at /etc/nginx/certs/${domains[0]}.crt
30- # Grab the expiration time of the certificate
29+ # Wait for the certificate to be issued, then record its serial number.
3130wait_for_symlink " ${domains[0]} " " $le_container_name "
32- first_cert_expire =" $( get_cert_date_epoch expiration " ${domains[0]} " " $le_container_name " ) "
31+ first_serial =" $( get_cert_serial " ${domains[0]} " " $le_container_name " ) "
3332
3433# Just to be sure
3534sleep 5
3635
37- # Issue a forced renewal
38- docker exec " $le_container_name " /app/force_renew & > /dev/null
36+ # Issue a forced renewal (capture the output so a failure is diagnosable).
37+ renew_output= " $( docker exec " $le_container_name " /app/force_renew 2>&1 ) "
3938
40- # Poll until expiration date changes or timeout
41- # Use a longer sleep and add error handling for transient states
39+ # A renewal re-issues the cert, so its serial must change.
4240timeout=$(( $(date +% s) + 30 ))
43- second_cert_expire =" $first_cert_expire "
41+ second_serial =" $first_serial "
4442while [[ $( date +%s) -lt $timeout ]]; do
45- # Try to get the new expiration date, but handle errors gracefully
46- new_expire=" $( get_cert_date_epoch expiration " ${domains[0]} " " $le_container_name " 2> /dev/null || echo " $first_cert_expire " ) "
47-
48- # Only update if we got a valid value (not empty and numeric)
49- if [[ -n " $new_expire " ]] && [[ " $new_expire " =~ ^[0-9]+$ ]]; then
50- second_cert_expire=" $new_expire "
51-
52- # If the new certificate has a later expiration, renewal succeeded
53- if [[ $second_cert_expire -gt $first_cert_expire ]]; then
54- [[ " ${DRY_RUN:- } " == 1 ]] && echo " Certificate for ${domains[0]} was correctly renewed."
55- break
56- fi
43+ new_serial=" $( get_cert_serial " ${domains[0]} " " $le_container_name " 2> /dev/null || true) "
44+ if [[ -n " $new_serial " && " $new_serial " != " $first_serial " ]]; then
45+ second_serial=" $new_serial "
46+ [[ " ${DRY_RUN:- } " == 1 ]] && echo " Certificate for ${domains[0]} was correctly renewed."
47+ break
5748 fi
58-
5949 sleep 2
6050done
6151
62- # Final check - verify renewal actually happened
63- if ! [[ $second_cert_expire -gt $first_cert_expire ]]; then
64- echo " Certificate for ${domains[0]} was not correctly renewed within 30s."
65- echo " First certificate expiration epoch : $first_cert_expire . "
66- echo " Second certificate expiration epoch : $second_cert_expire . "
52+ # Final check - verify the certificate was actually re-issued.
53+ if [[ " $second_serial " == " $first_serial " ]]; then
54+ echo " Certificate for ${domains[0]} was not correctly renewed within 30s (serial unchanged: $first_serial ) ."
55+ echo " force_renew output: "
56+ echo " $renew_output "
6757fi
0 commit comments