From 7fa24128fc9ee217f25f5aef19a0d01db2cc37f9 Mon Sep 17 00:00:00 2001 From: Roy Marples Date: Fri, 16 Nov 2007 10:37:54 +0000 Subject: [PATCH 1/1] resolvconf -s now does service commands so subscribers don't need to know about how to restart services on all platforms. --- dnsmasq | 20 ++------------------ libc | 11 +---------- named | 15 +-------------- resolvconf | 50 ++++++++++++++++++++++++++++++++++++++++++++++++++ resolvconf.8 | 8 +++++++- 5 files changed, 61 insertions(+), 43 deletions(-) diff --git a/dnsmasq b/dnsmasq index dbc6815..8b104ec 100755 --- 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 13a0521..ba0cbdd 100755 --- 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 86cbf7c..842998c 100755 --- 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 diff --git a/resolvconf b/resolvconf index 55e6214..a0e046d 100755 --- a/resolvconf +++ b/resolvconf @@ -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 diff --git a/resolvconf.8 b/resolvconf.8 index 70943b3..a8fcd4e 100644 --- a/resolvconf.8 +++ b/resolvconf.8 @@ -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 -- 1.7.1