|
13 | 13 | # shellcheck disable=SC2034 # read by the mode scripts |
14 | 14 | FIRST_PASS=true |
15 | 15 |
|
16 | | -# Set when certificates have been renewed but not yet applied to haproxy. |
17 | | -# Survives across passes, so a failed apply is retried on the next one. Starts |
18 | | -# set so every container start republishes the evidence: what a previous run |
19 | | -# left in /evidences may list removed domains or an old account, or be half |
20 | | -# published. |
21 | | -APPLY_PENDING=true |
| 16 | +# Set when certificates have changed but haproxy, or the evidence, does not |
| 17 | +# show them yet. They survive across passes, so a failed step is retried on the |
| 18 | +# next one, and only that step: evidence that keeps failing must not reload |
| 19 | +# haproxy on every retry, as each reload leaves the old workers holding their |
| 20 | +# connections for up to TIMEOUT_CLIENT. Both start set so every container start |
| 21 | +# republishes the evidence: what a previous run left in /evidences may list |
| 22 | +# removed domains or an old account, or be half published. |
| 23 | +RELOAD_PENDING=true |
| 24 | +EVIDENCE_PENDING=true |
22 | 25 |
|
23 | 26 | build_combined_pems() { |
24 | 27 | local domain fullchain privkey combined |
@@ -84,29 +87,33 @@ run_pass() { |
84 | 87 | done <<<"$(get-all-domains.sh)" |
85 | 88 |
|
86 | 89 | if [ "$changed" -eq 1 ]; then |
87 | | - APPLY_PENDING=true |
| 90 | + RELOAD_PENDING=true |
| 91 | + EVIDENCE_PENDING=true |
88 | 92 | fi |
89 | 93 |
|
90 | 94 | # Applying is separate from renewing, and retried until it sticks. A |
91 | 95 | # renewal that reaches disk but not haproxy is invisible: the next pass |
92 | 96 | # sees a fresh certificate, reports "nothing to renew", and never reloads |
93 | 97 | # again -- so haproxy would serve the pre-renewal certificate until it |
94 | 98 | # expires, which is soon, because being near expiry is why it renewed. |
95 | | - if [ "$APPLY_PENDING" = true ]; then |
96 | | - local applied=true |
97 | | - collect_evidence || { echo "Evidence generation failed" >&2; applied=false; } |
98 | | - build_combined_pems || { echo "Combined PEM build failed" >&2; applied=false; } |
99 | | - haproxy_reload || applied=false |
100 | | - if [ "$applied" = true ]; then |
101 | | - APPLY_PENDING=false |
| 99 | + if [ "$EVIDENCE_PENDING" = true ]; then |
| 100 | + if collect_evidence; then |
| 101 | + EVIDENCE_PENDING=false |
102 | 102 | else |
103 | | - echo "[$(date)] Certificate apply incomplete; retrying on the next pass" >&2 |
| 103 | + echo "[$(date)] Evidence generation failed; retrying on the next pass" >&2 |
| 104 | + fi |
| 105 | + fi |
| 106 | + if [ "$RELOAD_PENDING" = true ]; then |
| 107 | + if build_combined_pems && haproxy_reload; then |
| 108 | + RELOAD_PENDING=false |
| 109 | + else |
| 110 | + echo "[$(date)] Certificate apply failed; retrying on the next pass" >&2 |
104 | 111 | fi |
105 | 112 | fi |
106 | 113 | FIRST_PASS=false |
107 | 114 | [ "$failed" -eq 0 ] || return 1 |
108 | 115 | # Not a quiet pass either: wait the retry backoff, not RENEW_INTERVAL. |
109 | | - [ "$APPLY_PENDING" = false ] || return 3 |
| 116 | + [ "$RELOAD_PENDING" = false ] && [ "$EVIDENCE_PENDING" = false ] || return 3 |
110 | 117 | } |
111 | 118 |
|
112 | 119 | # $1: seconds to wait before the first pass, for a caller that has just run one. |
|
0 commit comments