From 47099e2855884feb782479172803cf3e4baf4297 Mon Sep 17 00:00:00 2001 From: WaLLy3K Date: Fri, 22 Sep 2017 03:56:53 +1000 Subject: [PATCH] Ensure resolver test occurs each second * Ensure that gravity will run the second the resolver is available * Increase timeout to 120s --- gravity.sh | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/gravity.sh b/gravity.sh index 881fc6f2..6c3e9ec6 100755 --- a/gravity.sh +++ b/gravity.sh @@ -77,14 +77,14 @@ gravity_DNSLookup() { fi # Determine if $lookupDomain is resolvable - if timeout 5 getent hosts "${lookupDomain}" &> /dev/null; then + if timeout 1 getent hosts "${lookupDomain}" &> /dev/null; then # Print confirmation of resolvability if it had previously failed if [[ -n "${secs:-}" ]]; then echo -e "${OVER} ${TICK} DNS resolution is now available\\n" fi return 0 elif [[ -n "${secs:-}" ]]; then - echo -e "${OVER} ${CROSS} DNS resolution is still unavailable, cancelling" + echo -e "${OVER} ${CROSS} DNS resolution is not available" exit 1 fi @@ -96,13 +96,15 @@ gravity_DNSLookup() { "${PIHOLE_COMMAND}" restartdns fi - # Give time for DNS server to be resolvable - secs="30" - while [[ "${secs}" -ne 0 ]]; do - [[ "${secs}" -ne 1 ]] && plural="s" - echo -ne "${OVER} ${INFO} Waiting $secs second${plural} before continuing..." - sleep 1 + # Ensure DNS server is given time to be resolvable + secs="120" + echo -ne " ${INFO} Waiting up to ${secs} seconds before continuing..." + until timeout 1 getent hosts "${lookupDomain}" &> /dev/null; do + [[ "${secs:-}" -eq 0 ]] && break + [[ "${secs:-}" -ne 1 ]] && plural="s" + echo -ne "${OVER} ${INFO} Waiting up to ${secs} second${plural} before continuing..." : $((secs--)) + sleep 1 done # Try again