From 4edffee19a8848641cc05b0c1890277a0ac5891d Mon Sep 17 00:00:00 2001 From: Frank Brehm Date: Wed, 18 Jan 2023 13:53:58 +0100 Subject: [PATCH] Fixing loading zone file in scripts/create-pdns-zones-from-files --- scripts/create-pdns-zones-from-files | 35 ++++++++++++++++++++++++---- 1 file changed, 30 insertions(+), 5 deletions(-) diff --git a/scripts/create-pdns-zones-from-files b/scripts/create-pdns-zones-from-files index 03825ff..a1b7762 100755 --- a/scripts/create-pdns-zones-from-files +++ b/scripts/create-pdns-zones-from-files @@ -24,6 +24,9 @@ CUSTOMER='DNS:NET' TSIG_KEY='pp-dns.com' ERRORS="0" +RETRIES_GET_ZONE_AFTER_CREATE=5 +WAIT_FOR_ZONE=1 + declare -a ZONE_FILES=() # shellcheck disable=SC2034 @@ -204,7 +207,29 @@ create_zone() { else debug "Executing: ${cmd}" # shellcheck disable=SC2086 - eval ${cmd} 2>&1 | grep -vi 'gpgsql Connection successful' + eval ${cmd} || true + fi + + local i=0 + existing='' + if [[ "${SIMULATE}" != 'y' ]] ; then + while [[ "$i" -lt "${RETRIES_GET_ZONE_AFTER_CREATE}" ]] ; do + debug "Waiting for zone '${CYAN}${zone}${NORMAL}' ..." + sleep "${WAIT_FOR_ZONE}" + existing=$( pdnsutil list-zone "${zone}" 2>&1 | \ + grep -vi 'gpgsql Connection successful' | \ + grep -w 'SOA' || true ) + if [[ -n "${existing}" ]] ; then + info "Found SOA for zone '${CYAN}${zone}${NORMAL}': ${existing}" + break + fi + i=$(( i + 1 )) + wait "${WAIT_FOR_ZONE}" + done + if [[ -z "${existing}" ]] ; then + error "Did not found SOA for zone '${CYAN}${zone}${NORMAL}' after ${RED}${RETRIES_GET_ZONE_AFTER_CREATE}${NORMAL} seconds." + exit 7 + fi fi cmd="pdnsutil set-account \"${zone}\" \"${CUSTOMER}\"" @@ -213,7 +238,7 @@ create_zone() { else debug "Executing: ${cmd}" # shellcheck disable=SC2086 - eval ${cmd} 2>&1 | grep -vi 'gpgsql Connection successful' + eval ${cmd} fi cmd="pdnsutil set-kind \"${zone}\" \"master\"" @@ -222,7 +247,7 @@ create_zone() { else debug "Executing: ${cmd}" # shellcheck disable=SC2086 - eval ${cmd} 2>&1 | grep -vi 'gpgsql Connection successful' + eval ${cmd} fi cmd="pdnsutil set-meta \"${zone}\" \"SOA-EDIT-API\" \"DEFAULT\"" @@ -231,7 +256,7 @@ create_zone() { else debug "Executing: ${cmd}" # shellcheck disable=SC2086 - eval ${cmd} 2>&1 | grep -vi 'gpgsql Connection successful' + eval ${cmd} fi cmd="pdnsutil set-meta \"${zone}\" \"TSIG-ALLOW-AXFR\" \"${TSIG_KEY}\"" @@ -240,7 +265,7 @@ create_zone() { else debug "Executing: ${cmd}" # shellcheck disable=SC2086 - eval ${cmd} 2>&1 | grep -vi 'gpgsql Connection successful' + eval ${cmd} fi } -- 2.39.5