From a57d539098aefc390900162f3a5e891dd91eddc0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20K=C3=B6nig?= Date: Tue, 3 Sep 2024 23:02:15 +0200 Subject: [PATCH 1/3] Remove leftover DNS check via dig as it now only doubles what we already have with getent hosts MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Christian König --- gravity.sh | 12 ------------ 1 file changed, 12 deletions(-) diff --git a/gravity.sh b/gravity.sh index d1664394..6a8918db 100755 --- a/gravity.sh +++ b/gravity.sh @@ -308,18 +308,6 @@ gravity_CheckDNSResolutionAvailable() { exit 1 fi - # If the /etc/resolv.conf contains resolvers other than 127.0.0.1 then the local dnsmasq will not be queried and pi.hole is NXDOMAIN. - # This means that even though name resolution is working, the getent hosts check fails and the holddown timer keeps ticking and eventually fails - # So we check the output of the last command and if it failed, attempt to use dig +short as a fallback - if timeout 4 dig +short "${lookupDomain}" &>/dev/null; then - 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 not available" - exit 1 - fi # Determine error output message if pgrep pihole-FTL &>/dev/null; then From ba2d10c65eca2fcf205b9d82a2d1901df5f946e5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20K=C3=B6nig?= Date: Tue, 3 Sep 2024 23:03:59 +0200 Subject: [PATCH 2/3] DNS check in gravity should not check for FTL as it might not be the host's name server MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Christian König --- gravity.sh | 8 -------- 1 file changed, 8 deletions(-) diff --git a/gravity.sh b/gravity.sh index 6a8918db..7ca695f5 100755 --- a/gravity.sh +++ b/gravity.sh @@ -309,14 +309,6 @@ gravity_CheckDNSResolutionAvailable() { fi - # Determine error output message - if pgrep pihole-FTL &>/dev/null; then - echo -e " ${CROSS} DNS resolution is currently unavailable" - else - echo -e " ${CROSS} DNS service is not running" - "${PIHOLE_COMMAND}" restartdns - fi - # Ensure DNS server is given time to be resolvable secs="120" echo -ne " ${INFO} Time until retry: ${secs}" From f80efa51aac22611ff5d0fa031c80cd7b1287e39 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20K=C3=B6nig?= Date: Tue, 3 Sep 2024 23:20:00 +0200 Subject: [PATCH 3/3] Wait until DNS resolution is available MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Christian König --- gravity.sh | 27 ++++++++++----------------- 1 file changed, 10 insertions(+), 17 deletions(-) diff --git a/gravity.sh b/gravity.sh index 7ca695f5..1ac0e282 100755 --- a/gravity.sh +++ b/gravity.sh @@ -298,29 +298,22 @@ gravity_CheckDNSResolutionAvailable() { # Determine if $lookupDomain is resolvable if timeout 4 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 + echo -e "${OVER} ${TICK} DNS resolution is available\\n" return 0 - elif [[ -n "${secs:-}" ]]; then - echo -e "${OVER} ${CROSS} DNS resolution is not available" - exit 1 + else + echo -e " ${CROSS} DNS resolution is currently unavailable" fi - - # Ensure DNS server is given time to be resolvable - secs="120" - echo -ne " ${INFO} Time until retry: ${secs}" - until timeout 1 getent hosts "${lookupDomain}" &>/dev/null; do - [[ "${secs:-}" -eq 0 ]] && break - echo -ne "${OVER} ${INFO} Time until retry: ${secs}" - : $((secs--)) + echo -e " ${INFO} Waiting until DNS resolution is available..." + until getent hosts github.com &> /dev/null; do + # Append one dot for each second waiting + str="${str}." + echo -ne " ${OVER} ${INFO} ${str}" sleep 1 done - # Try again - gravity_CheckDNSResolutionAvailable + # If we reach this point, DNS resolution is available + echo -e "${OVER} ${TICK} DNS resolution is available" } # Retrieve blocklist URLs and parse domains from adlist.list