Skip to content

Commit 05da2c1

Browse files
authored
Merge pull request #352 from devopswithnaman/fix/auto-renew-exit-code-handling
Fix exit code handling in auto-renew function
2 parents 936cb77 + b92ba4d commit 05da2c1

1 file changed

Lines changed: 16 additions & 12 deletions

File tree

command-functions

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -38,19 +38,23 @@ cmd-letsencrypt-auto-renew() {
3838
# For all apps, sorted by ascending time left until renewal.
3939
# This way, we'll prioritize apps that need to be renewed soon
4040
# if we should hit a rate limit along the way.
41-
fn-letsencrypt-list-apps-with-expiry \
42-
| sort -nk5 \
43-
| while IFS=$'\t' read -r -a appExpiry; do
44-
45-
if [[ ${appExpiry[4]} -lt 0 ]]; then
46-
dokku_log_info1 "${appExpiry[0]} needs renewal"
47-
dokku letsencrypt:enable "${appExpiry[0]}" || EXIT_CODE=$?
48-
else
49-
days_left=$(fn-letsencrypt-format-timediff "${appExpiry[4]}")
50-
dokku_log_verbose "${appExpiry[0]} still has $days_left days left before renewal"
41+
# Store the list in a temporary file to avoid subshell issues with pipelines
42+
local temp_file=$(mktemp)
43+
fn-letsencrypt-list-apps-with-expiry | sort -nk5 > "$temp_file"
44+
45+
while IFS=$'\t' read -r -a appExpiry; do
46+
if [[ ${appExpiry[4]} -lt 0 ]]; then
47+
dokku_log_info1 "${appExpiry[0]} needs renewal"
48+
if ! dokku letsencrypt:enable "${appExpiry[0]}"; then
49+
EXIT_CODE=1
5150
fi
52-
53-
done
51+
else
52+
days_left=$(fn-letsencrypt-format-timediff "${appExpiry[4]}")
53+
dokku_log_verbose "${appExpiry[0]} still has $days_left days left before renewal"
54+
fi
55+
done < "$temp_file"
56+
57+
rm -f "$temp_file"
5458

5559
dokku_log_info2 "Finished auto-renewal"
5660
if [[ "$EXIT_CODE" != 0 ]]; then

0 commit comments

Comments
 (0)