Release openresolv-3.4.1
[openresolv] / unbound.in
index 2f44dea252aa502e818d0b68af3b810255931bbf..b5fb7ecf53401c617060fb7776f0d4602aef6e31 100644 (file)
 [ -z "$RESOLVCONF" ] && eval "$(@PREFIX@/sbin/resolvconf -v)"
 
 : ${unbound_pid:=/var/run/unbound.pid}
-: ${unbound_restart:=@RESTARTCMD unbound@}
+: ${unbound_service:=unbound}
+: ${unbound_restart:=@RESTARTCMD ${unbound_service}@}
 newconf="# Generated by resolvconf\n"
 
 for d in $DOMAINS; do
        dn="${d%%:*}"
        ns="${d#*:}"
-       newconf="\n${newconf}forward-zone:\n\tname: \"$dn\"\n"
+       newconf="${newconf}\nforward-zone:\n\tname: \"$dn\"\n"
        while [ -n "$ns" ]; do
                newconf="${newconf}\tforward-addr: ${ns%%,*}\n"
                [ "$ns" = "${ns#*,}" ] && break
@@ -47,7 +48,7 @@ for d in $DOMAINS; do
 done
 
 if [ -n "$NAMESERVERS" ]; then
-       newconf="\n${newconf}forward-zone:\n\tname: \".\"\n"
+       newconf="${newconf}\nforward-zone:\n\tname: \".\"\n"
        for n in $NAMESERVERS; do
                newconf="${newconf}\tforward-addr: $n\n"
        done
@@ -57,11 +58,12 @@ if [ ! -f "$unbound_conf" ] || \
        [ "$(cat "$unbound_conf")" != "$(printf "$newconf")" ]
 then
        printf "$newconf" >"$unbound_conf"
-       #if [ -s "$unbound_pid" ] && \
-       #       kill -0 $(cat "$unbound_pid") 2>/dev/null
-       #then
-       #       unbound-control reload
-       #else
+       # If we can't sent a HUP then force a restart
+       if [ -s "$unbound_pid" ]; then
+               if ! kill -HUP $(cat "$unbound_pid") 2>/dev/null; then
+                       eval $unbound_restart
+               fi
+       else
                eval $unbound_restart
-       #fi
+       fi
 fi