diff --git a/ingress.tjo.cloud/root/etc/default/dyndns b/ingress.tjo.cloud/root/etc/default/dyndns index 11fd19c..9223d94 100644 --- a/ingress.tjo.cloud/root/etc/default/dyndns +++ b/ingress.tjo.cloud/root/etc/default/dyndns @@ -7,5 +7,8 @@ # The domain your subdomain is registered at. (i.e. foo.com for home.foo.com) DOMAIN=ingress.tjo.cloud +# Enable to make DELETE requests. +DESTRUCTIVE=true + # Account ID DNSIMPLE_ACCOUNT_ID=155200 \ No newline at end of file diff --git a/ingress.tjo.cloud/root/usr/local/bin/dyndns b/ingress.tjo.cloud/root/usr/local/bin/dyndns index 45d7d25..040e48e 100755 --- a/ingress.tjo.cloud/root/usr/local/bin/dyndns +++ b/ingress.tjo.cloud/root/usr/local/bin/dyndns @@ -156,7 +156,6 @@ healthcheck() { while (true); do domain_records=$(dnsimple::record::list) - log::debug "domain_records=$domain_records" for service in "${services[@]}"; do log::info "service=$service Discovering public IP address..." @@ -179,6 +178,19 @@ while (true); do configure::single "$domain_records" "$CLOUD_REGION" "$ipv4" "A" configure::many "$domain_records" "any" "$ipv4" "A" fi + + log::info "type=A Checking for stale records..." + echo "$domain_records" | jq -r ".data[] | select(.type == \"A\" and .name != \"$CLOUD_REGION\") | .id" | while read -r record_id; do + record_name=$(echo "$domain_records" | jq -r ".data[] | select(.id == $record_id) | .name") + record_ip=$(echo "$domain_records" | jq -r ".data[] | select(.id == $record_id) | .content") + log::info "type=A domain=$record_name ip=$record_ip Checking..." + if ! healthcheck "$record_ip"; then + log::warn "type=A domain=$record_name ip=$record_ip Unhealthy..." + dnsimple::record::delete "$record_id" + else + log::info "type=A domain=$record_name ip=$record_ip Healthy..." + fi + done fi if [[ -z $ipv6 ]]; then @@ -189,34 +201,21 @@ while (true); do configure::single "$domain_records" "$CLOUD_REGION" "$ipv6" "AAAA" configure::many "$domain_records" "any" "$ipv6" "AAAA" fi + + log::info "type=AAAA Checking for stale records..." + echo "$domain_records" | jq -r ".data[] | select(.type == \"AAAA\" and .name != \"$CLOUD_REGION\") | .id" | while read -r record_id; do + record_name=$(echo "$domain_records" | jq -r ".data[] | select(.id == $record_id) | .name") + record_ip=$(echo "$domain_records" | jq -r ".data[] | select(.id == $record_id) | .content") + log::info "type=AAAA domain=$record_name ip=$record_ip Checking..." + if ! healthcheck "[$record_ip]"; then + log::warn "type=AAAA domain=$record_name ip=$record_ip Unhealthy..." + dnsimple::record::delete "$record_id" + else + log::info "type=AAAA domain=$record_name ip=$record_ip Healthy..." + fi + done fi - log::info "type=A Checking for stale records..." - echo "$domain_records" | jq -r ".data[] | select(.type == \"A\" and .name != \"$CLOUD_REGION\") | .id" | while read -r record_id; do - record_name=$(echo "$domain_records" | jq -r ".data[] | select(.id == $record_id) | .name") - record_ip=$(echo "$domain_records" | jq -r ".data[] | select(.id == $record_id) | .content") - log::info "type=A domain=$record_name ip=$record_ip Checking..." - if ! healthcheck "$record_ip"; then - log::warn "type=A domain=$record_name ip=$record_ip Unhealthy..." - dnsimple::record::delete "$record_id" - else - log::info "type=A domain=$record_name ip=$record_ip Healthy..." - fi - done - - log::info "type=AAAA Checking for stale records..." - echo "$domain_records" | jq -r ".data[] | select(.type == \"AAAA\" and .name != \"$CLOUD_REGION\") | .id" | while read -r record_id; do - record_name=$(echo "$domain_records" | jq -r ".data[] | select(.id == $record_id) | .name") - record_ip=$(echo "$domain_records" | jq -r ".data[] | select(.id == $record_id) | .content") - log::info "type=AAAA domain=$record_name ip=$record_ip Checking..." - if ! healthcheck "[$record_ip]"; then - log::warn "type=AAAA domain=$record_name ip=$record_ip Unhealthy..." - dnsimple::record::delete "$record_id" - else - log::info "type=AAAA domain=$record_name ip=$record_ip Healthy..." - fi - done - log::info "Sleeping for $sleep_interval seconds..." sleep "$sleep_interval" done