From: Frank Brehm Date: Wed, 18 Jan 2023 12:53:58 +0000 (+0100) Subject: Fixing loading zone file in scripts/create-pdns-zones-from-files X-Git-Tag: 0.8.2^2~1 X-Git-Url: https://git.uhu-banane.org/?a=commitdiff_plain;h=4edffee19a8848641cc05b0c1890277a0ac5891d;p=pixelpark%2Fpp-admin-tools.git Fixing loading zone file in scripts/create-pdns-zones-from-files --- 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 }