Remove resolvconf -s support.
authorRoy Marples <roy@marples.name>
Tue, 21 Apr 2009 21:30:41 +0000 (21:30 +0000)
committerRoy Marples <roy@marples.name>
Tue, 21 Apr 2009 21:30:41 +0000 (21:30 +0000)
Instead we build how to restart services into each subscriber.
This is also configurable in resolvconf.conf.

Also, pdns_recursor has no global forward support, so don't attempt to
fudge a configuation for it.

Makefile
dnsmasq.in
libc.in
named.in
pdns_recursor.in
resolvconf.8.in
resolvconf.in

index c38186dfbec3048b4b562bc2f6e19ff5dc3fa7b6..7a46ba19c764f3f61004389d397cb330f87541e6 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -3,6 +3,7 @@ VERSION=        3.2
 PKG=           ${NAME}-${VERSION}
 
 INSTALL?=      install
+SED?=          sed
 PREFIX?=       /usr/local
 MANPREFIX?=    /usr/share
 VARBASE?=      /var
@@ -21,15 +22,26 @@ RESOLVCONF= resolvconf resolvconf.8 resolvconf.conf.5
 SUBSCRIBERS=   libc dnsmasq named pdns_recursor
 TARGET=                ${RESOLVCONF} ${SUBSCRIBERS}
 
+_CMD_SH=       if [ -x /sbin/rc-service ]; then \
+                       echo '/sbin/rc-service \\1 -- --ifstarted restart'; \
+               elif [ -d /etc/rc.d ]; then \
+                       echo '/etc/rc.d/\\1 status && /etc/rc.d/\\1 restart'; \
+               elif [ -d /etc/init.d ]; then \
+                       echo '/etc/init.d/\\1 status && /etc/rc.d/\\1 restart'; \
+               fi
+_CMD!=         ${_CMD_SH}
+RESTARTCMD?=   ${_CMD}$(shell ${_CMD_SH})
+
 .SUFFIXES: .in
 
 all: ${TARGET}
 
 .in:
-       sed -e 's:@PREFIX@:${PREFIX}:g' \
+       ${SED} -e 's:@PREFIX@:${PREFIX}:g' \
                -e 's:@SYSCONFDIR@:${SYSCONFDIR}:g' \
                -e 's:@LIBEXECDIR@:${LIBEXECDIR}:g' \
                -e 's:@VARDIR@:${VARDIR}:g' \
+               -e 's:@RESTARTCMD \(.*\)@:${RESTARTCMD}:g' \
                $@.in > $@
 
 clean:
index 56f0e8ef1ffea9cf2e79c171a50f8e4de9d8a54e..6d4e5af31d14957c9513ebdc6fdca72250100e53 100644 (file)
 [ -f "@SYSCONFDIR@"/resolvconf.conf ] || exit 0
 . "@SYSCONFDIR@/resolvconf.conf" || exit 1
 [ -z "$dnsmasq_conf" -o -z "$dnsmasq_resolv" ] && exit 0
-: ${RESOLVCONF:=resolvconf}
-[ -z "$NAMESERVERS" -a -z "$DOMAINS" ] && eval "$("$RESOLVCONF" -v)"
+[ -z "$RESOLVCONF" ] && eval "$(@PREFIX@/sbin/resolvconf -v)"
 
-dnsmasqpid="${dnsmasq_pid:-/var/run/dnsmasq.pid}"
+: ${dnsmasq_pid:=/var/run/dnsmasq.pid}
+: ${dnsmasq_restart:=@RESTARTCMD dnsmasq@}
 newconf="# Generated by resolvconf\n"
 newresolv="$newconf"
 
@@ -41,18 +41,17 @@ newresolv="$newconf"
 # whilst changing DNS options around. However, dbus support is optional
 # so we need to validate a few things first.
 # Check for DBus support in the binary
-
 dbus=false
-dbuspid="${dbus_pid:-/var/run/dbus/dbus.pid}"
-[ -s "$dbuspid" ] || dbuspid=/var/run/dbus.pid
-[ -s "$dbuspid" ] || dbuspid=/var/run/dbus/pid
-if [ -s "$dbuspid" -a -s "$dnsmasqpid" ]; then
+: ${dbus_pid:=/var/run/dbus/dbus.pid}
+[ -s "$dbus_pid" ] || dbuspid=/var/run/dbus.pid
+[ -s "$dbus_pid" ] || dbuspid=/var/run/dbus/pid
+if [ -s "$dbus_pid" -a -s "$dnsmasq_pid" ]; then
        if dnsmasq --version 2>/dev/null | \
                grep -q "^Compile time options.*[[:space:]]DBus[[:space:]]"
        then
                # Sanity - check that dnsmasq and dbus are running
-               if kill -0 $(cat "$dbuspid") 2>/dev/null && \
-                       kill -0 $(cat "$dnsmasqpid") 2>/dev/null
+               if kill -0 $(cat "$dbus_pid") 2>/dev/null && \
+                       kill -0 $(cat "$dnsmasq_pid") 2>/dev/null
                then
                        dbus=true
                        newconf="$newconf\n# Domain specific servers will"
@@ -108,14 +107,10 @@ else
 fi
 
 if $changed; then
-       if [ "$(command -v service)" = service ]; then
-               service dnsmasq restart
-       else
-               $RESOLVCONF -s dnsmasq restart
-       fi
+       $dnsmasq_restart
 fi
 if $dbus; then
-       $restart || kill -HUP $(cat "$dnsmasqpid")
+       $restart || kill -HUP $(cat "$dnsmasq_pid")
        # Send even if empty so old servers are cleared
        dbus-send --system --dest=uk.org.thekelleys.dnsmasq \
                /uk/org/thekelleys/dnsmasq uk.org.thekelleys.SetServers \
diff --git a/libc.in b/libc.in
index 5e392c1c29e9741b0461f8a57cadbef18bdc1bee..d763315c37d777a65e9256d981c9c09e6f77ad52 100644 (file)
--- a/libc.in
+++ b/libc.in
 # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
 # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 
-: ${RESOLVCONF:=resolvconf}
 SYSCONFDIR=@SYSCONFDIR@
 LIBEXECDIR=@LIBEXECDIR@
 VARDIR=@VARDIR@
-IFACEDIR="${VARDIR}/interfaces"
+IFACEDIR="$VARDIR/interfaces"
 
 # sed may not be available, and this is faster on small files
 key_get_value()
@@ -78,6 +77,8 @@ elif [ -d "$SYSCONFDIR"/resolvconf ]; then
        fi
 fi
 : ${resolv_conf:=/etc/resolv.conf}
+: ${libc_restart:=@RESTARTCMD nscd@}
+: ${list_resolv:=@PREFIX@/sbin/resolvconf -l}
 
 uniqify()
 {
@@ -104,7 +105,7 @@ case "${resolv_conf_passthrough:-NO}" in
        newconf="$(cat "$newest")\n"
        ;;
 *)
-       [ -z "$NAMESERVERS" -a -z "$SEARCH" ] && eval "$("$RESOLVCONF" -v)"
+       [ -z "$RESOLVCONF" ] && eval "$(@PREFIX@/sbin/resolvconf -v)"
        newsearch="$(uniqify $search_domains $SEARCH)"
        newns="$(uniqify $name_servers $NAMESERVERS)"
 
@@ -120,11 +121,7 @@ case "${resolv_conf_passthrough:-NO}" in
 
        # Now get any configured options
        opts="$resolv_conf_options${resolv_conf_options:+ }"
-       if [ "$(command -v list_resolv)" = list_resolv ]; then
-               opts="$opts$(list_resolv -l | key_get_value "options ")"
-       else
-               opts="$opts$($RESOLVCONF -l | key_get_value "options ")"
-       fi
+       opts="$opts$($list_resolv | key_get_value "options ")"
        if [ -n "$opts" ]; then
                newconf="${newconf}options"
                for opt in $(uniqify $opts); do
@@ -133,7 +130,7 @@ case "${resolv_conf_passthrough:-NO}" in
                newconf="$newconf\n"
        fi
 
-       if [ -n "resolv_conf_tail" ]; then
+       if [ -n "$resolv_conf_tail" ]; then
                newconf="$newconf$resolv_conf_tail\n"
        fi
        ;;
@@ -146,17 +143,13 @@ fi
 
 # Create our resolv.conf now
 (umask 022; printf "$newconf" >"$resolv_conf")
-if [ "$(command -v service)" = service ]; then
-       service nscd restart
-else
-       $RESOLVCONF -s nscd restart
-fi
+$libc_restart
 
 retval=0
 # Notify users of the resolver
 for script in "$LIBEXECDIR"/libc.d/*; do
        if [ -f "$script" -a -x "$script" ]; then
-               RESOLVCONF="$RESOLVCONF" "$script" "$@"
+               "$script" "$@"
                retval=$(($retval + $?))
        fi
 done
index 1b38a015859e3c426aba4c7d06b3d66a66148923..401340eb7a8e2efc806ec7be7806f9371a05875f 100644 (file)
--- a/named.in
+++ b/named.in
 [ -f "@SYSCONFDIR@"/resolvconf.conf ] || exit 0
 . "@SYSCONFDIR@/resolvconf.conf" || exit 1
 [ -z "$named_zones" -o -z "$named_options" ] && exit 0
-: ${RESOLVCONF:=resolvconf}
-[ -z "$NAMESERVERS" -a -z "$DOMAINS" ] && eval "$("$RESOLVCONF" -v)"
+[ -z "$RESOLVCONF" ] && eval "$(@PREFIX@/sbin/resolvconf -v)"
 
+: ${named_restart:=@RESTARTCMD named@}
 newoptions="# Generated by resolvconf\n"
 newzones="$newoptions"
+
 forward=
 for n in $NAMESERVERS; do
        case "$forward" in
@@ -75,10 +76,5 @@ then
 fi
 
 if $changed; then
-       if [ "$(command -v service)" = service ]; then
-               service named restart
-       else
-               $RESOLVCONF -s named restart
-       fi
+       $named_restart
 fi
-exit 0
index b96808430f60578d685aec7edf4c02511ff85ba8..ffe4da8cb0281c278a6aec52ca2e657327b9ee4d 100755 (executable)
 [ -f "@SYSCONFDIR@"/resolvconf.conf ] || exit 0
 . "@SYSCONFDIR@/resolvconf.conf" || exit 1
 [ -z "$pdns_zones" ] && exit 0
-: ${RESOLVCONF:=resolvconf}
-[ -z "$NAMESERVERS" -a -z "$DOMAINS" ] && eval "$("$RESOLVCONF" -v)"
+[ -z "$RESOLVCONF" ] && eval "$(@PREFIX@/sbin/resolvconf -v)"
+
+: ${pdns_restart:=@RESTARTCMD pdns_recursor@}
 
 newzones=
-for n in $NAMESERVERS; do
-       newzones="$newzones${newzones:+,}$n"
-done
-[ -n "$newzones" ] && newzones=".=$newzones\n"
 
-dbusdest=
+# pds_recursor does not present support global forward servers, which
+# does limit it's usefulness somewhat.
+# If it did, the below code can be enabled, or something like it.
+#for n in $NAMESERVERS; do
+#      newzones="$newzones${newzones:+,}$n"
+#done
+#[ -n "$newzones" ] && newzones=".=$newzones\n"
+
 for d in $DOMAINS; do
        newns=
        ns="${d#*:}"
@@ -54,9 +58,5 @@ if [ ! -f "$pdns_zones" ] || \
        [ "$(cat "$pdns_zones")" != "$(printf "$newzones")" ]
 then
        printf "$newzones" >"$pdns_zones"
-       if [ "$(command -v service)" = service ]; then
-               service pdns_recursor restart
-       else
-               $RESOLVCONF -s pdns_recursor restart
-       fi
+       $pdns_restart
 fi
index dcecc43e63e6bde93fe76e0fed209f6dece89ad3..fea3cd6b820981dcef4d9f86116080294c377ff7 100644 (file)
@@ -22,7 +22,7 @@
 .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
 .\" SUCH DAMAGE.
 .\"
-.Dd March 18, 2009
+.Dd April 21, 2009
 .Dt RESOLVCONF 8 SMM
 .Os
 .Sh NAME
@@ -138,15 +138,6 @@ what it already has for that interface.
 .Nm
 also has some options designed to be used by it's subscribers:-
 .Bl -tag -width indent
-.It Fl s Ar service Ar command ...
-Try and send the
-.Ar command
-to the system
-.Ar service .
-Normally this is something like
-.Ar resolvconf -s named restart .
-We have this command, so the subscribers don't have to know too much about the
-operating system on the host.
 .It Fl v
 Echo variables DOMAINS, SEARCH and NAMESERVERS so that the subscriber can
 configure the resolver easily.
@@ -214,6 +205,7 @@ for instructions on how to configure your resolver.
 .Xr dnsmasq 8 ,
 .Xr named 8 ,
 .Xr resolv.conf 5 ,
+.Xr resolvconf.conf 5 ,
 .Xr resolver 3 ,
 .Xr stdin 3
 .Sh AUTHORS
index feddaa0fb85a1e4cbf4a5444d32d42663fd63ffd..ea984bdf05567919316ec2f7ee052f291772a285 100644 (file)
@@ -73,7 +73,6 @@ usage()
                    pattern
          -v [\$PATTERN]    echo NEWDOMAIN, NEWSEARCH and NEWNS variables to
                           the console
-         -s \$SVC \$CMD     Do \$CMD for the system service \$SVC
          -h               Show this help cruft
        EOF
        [ -z "$1" ] && exit 0
@@ -258,60 +257,13 @@ make_vars()
        echo "NAMESERVERS='$(uniqify $NAMESERVERS)'"
 }
 
-# We do our service restarting here so that our subscribers don't have to know
-# about the OS's init system.
-service()
-{
-       local service="$1" action="$2"
-
-       [ -z "$action" ] && usage "Action not specified"
-       shift; shift
-
-       # If restarting check if service is running or not if we can
-       if [ "$action" = restart ]; then
-               if [ -s /var/run/"$service".pid ]; then
-                       kill -0 $(cat /var/run/"$service".pid) 2>/dev/null
-               elif [ -s /var/run/"$service"/"$service".pid ]; then
-                       kill -0 $(cat /var/run/"$service"/"$service".pid) \
-                               2>/dev/null
-               elif [ -s /var/run/"$service"/pid ]; then
-                       kill -0 $(cat /var/run/"$service"/pid) 2>/dev/null
-               else
-                       false
-               fi
-               # Service not running, so don't restart
-               [ $? != 0 ] && exit 0
-       fi      
-       if [ -x /sbin/service ]; then
-               service "$service" "$action" "$@" 
-       elif [ -x /etc/init.d/"$service" -a -x /sbin/runscript ]; then
-               if [ "$action" = "restart" ]; then
-                       /etc/init.d/"$service" --quiet --nodeps \
-                               conditionalrestart "$@"
-               else
-                       /etc/init.d/"$service" --quiet --nodeps \
-                               "$action" "$@"
-               fi
-       elif [ -x /etc/init.d/"$service" ]; then
-               /etc/init.d/"$service" "$action" "$@"
-       elif [ -x /etc/rc.d/"${service}" ]; then
-               /etc/rc.d/"$service" "$action" "$@" 
-       elif [ -x /etc/rc.d/rc."$service" ]; then
-               /etc/rc.d/rc."$service" "$action" "$@"
-       else
-               error_exit "Don't know how to interact with services on" \
-                       "this platform"
-       fi
-}
-
 force=false
-while getopts a:d:fhilm:ps:uv OPT; do
+while getopts a:d:fhilm:puv OPT; do
        case "$OPT" in
        f) force=true;;
        h) usage;;
        m) IF_METRIC="$OPTARG";;
        p) IF_PRIVATE=1;;
-       s) cmd=s; service="$OPTARG";;
        '?') ;;
        *) cmd="$OPT"; iface="$OPTARG";;
        esac
@@ -319,17 +271,13 @@ done
 shift $(($OPTIND - 1))
 args="$iface${iface:+ }$@"
 
-if [ "$cmd" = s ]; then
-       service "$service" "$@"
-       exit $?
-fi
-
 # -l lists our resolv files, optionally for a specific interface
 if [ "$cmd" = l -o "$cmd" = i ]; then
        list_resolv "$cmd" "$args"
        exit $?
 fi
 
+# Not normally needed, but subscribers should be able to run independently
 if [ "$cmd" = v ]; then
        make_vars "$iface"
        exit $?
@@ -433,6 +381,7 @@ if [ "$cmd" = a ]; then
 fi
 
 eval "$(make_vars)"
+: ${list_resolv:=list_resolv -l}
 retval=0
 for script in "$LIBEXECDIR"/*; do
        [ -f "$script" ] || continue