resolvconf -s now does service commands so subscribers don't need to know about how...
authorRoy Marples <roy@marples.name>
Fri, 16 Nov 2007 10:37:54 +0000 (10:37 +0000)
committerRoy Marples <roy@marples.name>
Fri, 16 Nov 2007 10:37:54 +0000 (10:37 +0000)
dnsmasq
libc
named
resolvconf
resolvconf.8

diff --git a/dnsmasq b/dnsmasq
index dbc68157a47bc5d0ca4e93a9688950fcc0598e29..8b104eca02ab00679f0dafe5db65bf4c095e9611 100755 (executable)
--- a/dnsmasq
+++ b/dnsmasq
@@ -149,25 +149,9 @@ else
        printf "${NEWRESOLV}" > "${DNSMASQRESOLV}"
 fi
 
-[ -x /sbin/runscript ] && INIT_EXTRA="--quiet --nodeps"
-
-if [ "${RELOAD}" = "yes" ]; then
-       if [ -x "${PREFIX}"/etc/init.d/dnsmasq ]; then
-               /etc/init.d/dnsmasq ${INIT_EXTRA} conditionalrestart
-       elif [ -x "${PREFIX}"/etc/rc.d/dnsmasq -a -s /var/run/dnsmasq.pid ]; then
-               kill -0 $(cat /var/run/dnsmasq.pid) && \
-               "${PREFIX}"/etc/rc.d/dnsmasq restart
-       fi
-fi
-
+[ "${RELOAD}" = "yes" ] && resolvconf -s dnsmasq restart
 if [ "${DBUS}" = "yes" ]; then
-       if [ "${RELOAD}" != "yes" ]; then
-               if [ -x "${PREFIX}"/etc/init.d/dnsmasq ]; then
-                       /etc/init.d/dnsmasq ${INIT_EXTRA} reload
-               elif [ -x "${PREFIX}"/etc/rc.d/dnsmasq ]; then
-                       "${PREFIX}"/etc/rc.d/dnsmasq reload
-               fi
-       fi
+       [ "${RELOAD}" != "yes" ] && resolvconf -s dnsmasq reload
        # Send even if emtpy 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 b/libc
index 13a0521455354b684fe9fdb67eda5108ab0be5ba..ba0cbdd46c6e77d22e53b7b8b63157e9df9e8494 100755 (executable)
--- a/libc
+++ b/libc
@@ -141,16 +141,7 @@ fi
 # Create our resolv.conf now
 printf "${NEWCONF}" > "${RESOLVCONF}"/run/resolv.conf
 
-# Restart nscd if it's running
-if [ -x /etc/init.d/nscd ]; then
-       if [ -x /sbin/runscript ]; then
-               /etc/init.d/nscd --nodeps --quiet conditionalrestart
-       else
-               /etc/init.d/nscd restart
-       fi
-elif [ -x /etc/rc.d/nscd ]; then
-       /etc/rc.d/nscd restart
-fi
+resolvconf -s nscd restart
 
 # Notify users of the resolver
 for x in "${REVOLVCONF}"/update-libc.d/*; do
diff --git a/named b/named
index 86cbf7c5ed74a75a33191782ea53d3d2559b60eb..842998cda71a61d6068a6a29fc2d5fbbffe8fe1d 100755 (executable)
--- a/named
+++ b/named
@@ -120,19 +120,6 @@ else
        RELOAD="yes"
 fi
 
-if [ "${RELOAD}" = "yes" ]; then
-       # OpenRC style
-       if [ -x /etc/init.d/named ]; then
-               if [ -x /sbin/runscript ]; then
-                       /etc/init.d/named --nodeps --quiet conditionalrestart
-               else
-                       /etc/init.d/named restart
-               fi
-       fi
-       # BSD RC style
-       if [ -x /etc/rc.d/named -a -s /var/run/named/pid ]; then
-               kill -0 $(cat /var/run/named/pid) && /etc/rc.d/named restart
-       fi
-fi
+[ "${RELOAD}" = "yes" ] && resolvconf -s named restart
 
 exit 0
index 55e621474cacee00a7ae1436daa680cf93b74b35..a0e046db68e1b493fe136c69e763affb4730d120 100755 (executable)
@@ -56,6 +56,7 @@ 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 "$@" ] && exit 0
@@ -86,6 +87,55 @@ if [ -n "$1" ]; then
        CMD="$1"
        shift
 fi
+
+# We do our service restarting here so that our subscribers don't have to know
+# about the OS's init system.
+if [ "x${CMD}" = "x-s" ]; then
+       if [ -n "$1" ]; then
+               SERVICE="$1"
+               shift
+       fi
+       [ -z "${SERVICE}" ] && usage "Service not specified"
+       if [ -n "$1" ]; then
+               ACTION="$1"
+               shift
+       fi
+       [ -z "${ACTION}" ] && usage "Action not specified"
+
+       # If restarting check if service is running or not if we can
+       if [ "x${ACTION}" = "xrestart" ]; then
+               if [ -s /var/run/"${SERVICE}".pid ]; then
+                       kill -0 $(cat /var/run/"${SERVICE}".pid)
+               elif [ -s /var/run/"${SERVICE}"/"${SERVICE}".pid ]; then
+                       kill -0 $(cat /var/run/"${SERVICE}".pid)
+               elif [ -s /var/run/"${SERVICE}"/pid ]; then
+                       kill -0 $(cat /var/run/"${SERVICE}"/pid)
+               else
+                       false
+               fi
+               # Service not running, so don't restart
+               [ $? != 0 ] && exit 1
+       fi      
+       if [ -x /sbin/service ]; then
+               service "${SERVICE}" "${ACTION}" "$@" 
+       elif [ -x /etc/init.d/"${SERVICE}" -a -x /sbin/runscript ]; then
+               if [ "x${ACTION}" = "xrestart" ]; 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
+       exit $?
+fi
+
 if [ -n "$1" ]; then
        IFACE="$1"
        shift
index 70943b39c2bf35ed5958b648237d9f31e5600a28..a8fcd4eefa4b1f3959bc7a6c7a8312c25409be61 100644 (file)
@@ -19,7 +19,9 @@ cat \fIFILE\fR |
 \fB\-i\fR \fIPATTERN\fR
 .PP
 .B resolvconf
-\fB\-v\fR \fIPATTERN\fr
+\fB\-v\fR \fIPATTERN\fR
+.B resolvconf
+\fB\-s\fR \fISERVICE COMMAND [args]\fR
 .SH DESCRIPTION
 Overwrite (\fB\-a\fR) or delete (\fB\-d\fR) the nameserver information
 record for network interface \fIINTERFACE\fR
@@ -36,6 +38,10 @@ with patterns to match interface names.
 With \fB\-v\fR, we echo variables NEWDOMAIN, NEWSEARCH and NEWNS to the
 console which can be used to make it easer writing scripts which configure
 DNS resolvers.
+.PP
+With \fB\-s\fR, we work out if the service is running by finding its pidfile
+and if it is we restart it. This means that only resolvconf needs to know this
+for supported platforms and subscribers can just call this resolvconf function.
 .SH SERVERS
 Normally
 .B resolvconf