bundles/unbound: automatically restart unbound if dns resolution fails for more than five minutes
All checks were successful
kunsi/bundlewrap/pipeline/head This commit looks good

This commit is contained in:
Franzi 2021-08-19 20:03:24 +02:00
parent 35938ead04
commit f0987ccb44
Signed by: kunsi
GPG key ID: 12E3D2136B818350
3 changed files with 29 additions and 0 deletions

View file

@ -0,0 +1,25 @@
#!/bin/bash
now="$(date +%s)"
resolved="$(dig +short kunbox.net)"
if [[ -n "$resolved" ]]
then
echo "$now" > /var/tmp/unbound_last_resolved
exit 0
fi
last_resolved="$(cat /var/tmp/unbound_last_resolved)"
five_min_ago="$(expr $now - 300)"
if [[ "$last_resolved" -lt "$five_min_ago" ]]
then
systemctl restart unbound
# Write "in 25 minutes" timestamp to /var/tmp/unbound_last_resolved.
# If resolving gets fixed by the restart, this will get re-written
# on the next run of this script. If not, this script will restart
# unbound again in half an hour (25min plus 5min grace time).
echo "$(expr $now + 1500)" > /var/tmp/unbound_last_resolved
fi