fix(ingress.tjo.cloud/dyndns): check ipv6 only if it has ipv6
Some checks failed
/ lint (push) Failing after 39s

This commit is contained in:
Tine 2025-01-06 20:35:39 +01:00
parent e996b3107d
commit a7d7e7b6ff
Signed by: mentos1386
SSH key fingerprint: SHA256:MNtTsLbihYaWF8j1fkOHfkKNlnN1JQfxEU/rBU8nCGw
2 changed files with 29 additions and 27 deletions

View file

@ -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

View file

@ -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