]> Frank Brehm's Git Trees - pixelpark/pp-admin-tools.git/commitdiff
Fixing loading zone file in scripts/create-pdns-zones-from-files
authorFrank Brehm <frank.brehm@pixelpark.com>
Wed, 18 Jan 2023 12:53:58 +0000 (13:53 +0100)
committerFrank Brehm <frank.brehm@pixelpark.com>
Wed, 18 Jan 2023 12:53:58 +0000 (13:53 +0100)
scripts/create-pdns-zones-from-files

index 03825ff74169b4ac719d6eefaac24d542b6683e4..a1b7762555000c7efcd13fd0b7219994fe8284ec 100755 (executable)
@@ -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
 
 }