From 90a418801d5b3669e10ef627886d893e9a749bd9 Mon Sep 17 00:00:00 2001 From: Tim Kimber Date: Tue, 15 Sep 2020 15:04:49 +0100 Subject: [PATCH] Add retry logic for "Bad Gateway" duckdns error --- dns_scripts/dns_add_duckdns | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/dns_scripts/dns_add_duckdns b/dns_scripts/dns_add_duckdns index 9f61c8c..9d1776a 100755 --- a/dns_scripts/dns_add_duckdns +++ b/dns_scripts/dns_add_duckdns @@ -10,8 +10,17 @@ fi domain="$1" txtvalue="$2" +i=1 response=$(curl --retry 5 --silent "https://www.duckdns.org/update?domains=${domain}&token=${token}&txt=${txtvalue}") + +while [[ "${response}" == *"502 Bad Gateway"* ]] && [ $i -le 5 ]; do + echo "Retrying Bad Gateway response (attempt $i of 5)" + sleep 5 + i=$((i+1)) + response=$(curl --retry 5 --silent "https://www.duckdns.org/update?domains=${domain}&token=${token}&txt=${txtvalue}") +done + if [ "$response" != "OK" ]; then echo "Failed to update TXT record for ${domain} at duckdns.org (is the TOKEN valid?)" echo "Response: $response"