better output for dynamic ip update failures
authorIan Kelling <ian@iankelling.org>
Sat, 14 Feb 2026 15:04:56 +0000 (10:04 -0500)
committerIan Kelling <ian@iankelling.org>
Sat, 14 Feb 2026 15:04:56 +0000 (10:04 -0500)
dynamic-ip-update

index f72ee0eac2334457a96a34bafa4365024e6be159..1238451a1aaa257acb9dbb3549d409cbc8f64590 100755 (executable)
@@ -20,8 +20,7 @@
 # See the License for the specific language governing permissions and
 # limitations under the License.
 
-
-set -e; . /usr/local/lib/bash-bear; set +e
+. /a/c/fsf-script-lib
 [[ $EUID == 0 ]] || exec sudo -E "${BASH_SOURCE[0]}" "$@"
 
 this_file="$(readlink -f -- "${BASH_SOURCE[0]}")"
@@ -161,8 +160,8 @@ main() {
   fi
 
   # if we failed to get our ipv6 addr, we probably have ipv6
-  # connectivity problem.
-  if [[ ! $ip6 ]]; then
+  # connectivity problem. But also just vary to ipv4 if we are failing.
+  if [[ ! $ip6 ]] || (( nsupdate_fails % 3 )); then
     ip_arg=-4
   fi
 
@@ -209,11 +208,25 @@ answer
 quit
 EOF
 
-  if $verbose; then echo "nsupdate stdin:"; cat $tmpf; fi
-  chronic nsupdate $ip_arg -k /p/c/user-specific/bind/etc/bind/Kb8.nz.*.private <$tmpf || nsupdate_fails=$((nsupdate_fails + 1))
+  nsupdate_fails_start=$nsupdate_fails
+  if ! mb chronic nsupdate $ip_arg -k /p/c/user-specific/bind/etc/bind/Kb8.nz.*.private <$tmpf; then
+    echo "nsupdate stdin:"; cat $tmpf
+    nsupdate_fails=$((nsupdate_fails + 1))
+  elif $verbose; then
+    echo "nsupdate stdin:"; cat $tmpf
+  fi
   sed -i 's/^server .*/server bk.b8.nz/' $tmpf
-  if $verbose; then echo "nsupdate stdin:"; cat $tmpf; fi
-  chronic nsupdate $ip_arg -k /p/c/user-specific/bind/etc/bind/Kb8.nz.*.private <$tmpf  || nsupdate_fails=$((nsupdate_fails + 1))
+  if ! chronic nsupdate $ip_arg -k /p/c/user-specific/bind/etc/bind/Kb8.nz.*.private <$tmpf; then
+    echo "nsupdate stdin:"; cat $tmpf
+    nsupdate_fails=$((nsupdate_fails + 1))
+  elif $verbose; then
+    echo "nsupdate stdin:"; cat $tmpf
+  fi
+
+  if (( nsupdate_fails_start == nsupdate_fails )); then
+    nsupdate_fails=0
+  fi
+
   if (( nsupdate_fails > nsupdate_fail_limit )); then
     echo error: nsupdate is persistently failing >&2
     exit 1
@@ -230,7 +243,7 @@ loop-main() {
 
 nsupdate_fails=0
 if [[ $PPID == 1 ]]; then
-  nsupdate_fail_limit=10
+  nsupdate_fail_limit=20
   loop-main
 else
   nsupdate_fail_limit=0