From: Andrew Tridgell Date: Mon, 4 Jun 2007 05:09:03 +0000 (+1000) Subject: split out the basic interface handling, and run event scripts in a deterministic... X-Git-Tag: tevent-0.9.20~348^2~2578 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=cc9f6d30d8d06a96dfdecb126266d6a2c06910c9;p=thirdparty%2Fsamba.git split out the basic interface handling, and run event scripts in a deterministic order (This used to be ctdb commit 399e993a4a233a5953e1e7264141e5c7c8c8c711) --- diff --git a/ctdb/Makefile.in b/ctdb/Makefile.in index 2770f8794f4..b475f528cc8 100644 --- a/ctdb/Makefile.in +++ b/ctdb/Makefile.in @@ -111,9 +111,10 @@ install: all install -m755 config/events $(DESTDIR)$(etcdir)/ctdb install -m755 config/functions $(DESTDIR)$(etcdir)/ctdb install -m755 config/statd-callout $(DESTDIR)$(etcdir)/ctdb - install -m755 config/events.d/samba $(DESTDIR)$(etcdir)/ctdb/events.d - install -m755 config/events.d/nfs $(DESTDIR)$(etcdir)/ctdb/events.d - install -m755 config/events.d/nfslock $(DESTDIR)$(etcdir)/ctdb/events.d + install -m755 config/events.d/10.interface $(DESTDIR)$(etcdir)/ctdb/events.d + install -m755 config/events.d/50.samba $(DESTDIR)$(etcdir)/ctdb/events.d + install -m755 config/events.d/59.nfslock $(DESTDIR)$(etcdir)/ctdb/events.d + install -m755 config/events.d/60.nfs $(DESTDIR)$(etcdir)/ctdb/events.d install -m755 tools/onnode.ssh $(DESTDIR)$(bindir) install -m755 tools/onnode.rsh $(DESTDIR)$(bindir) cd $(DESTDIR)$(bindir) && ln -sf onnode.ssh onnode diff --git a/ctdb/config/events b/ctdb/config/events index 9b0126d35d2..24b018446d6 100755 --- a/ctdb/config/events +++ b/ctdb/config/events @@ -1,87 +1,34 @@ #!/bin/sh ############################ # main event script for ctdb +# +# This script is called with one of the following sets of arguments +# startup : called when ctdb starts +# shutdown : called when ctdb shuts down +# takeip . /etc/ctdb/functions loadconfig ctdb +# ensure we have /bin and /usr/bin in the path +PATH=/bin:/usr/bin:$PATH + cmd="$1" shift case $cmd in - ############################# - # called when ctdbd starts up startup) + # make sure we have a blank state directory for the scripts to work with /bin/rm -rf /etc/ctdb/state /bin/mkdir -p /etc/ctdb/state ;; - - - ################################################ - # called when ctdbd wants to claim an IP address - takeip) - if [ $# != 3 ]; then - echo "must supply interface, IP and maskbits" - exit 1 - fi - iface=$1 - ip=$2 - maskbits=$3 - - /sbin/ip link set $iface up || { - echo "`/bin/date` Failed to bringup interface $iface" - exit 1 - } - /sbin/ip addr add $ip/$maskbits dev $iface || { - echo "`/bin/date` Failed to add $ip/$maskbits on dev $iface" - exit 1 - } - - # flush our route cache - echo 1 > /proc/sys/net/ipv4/route/flush - ;; - - - ################################################## - # called when ctdbd wants to release an IP address - releaseip) - if [ $# != 3 ]; then - echo "`/bin/date` must supply interface, IP and maskbits" - exit 1 - fi - iface=$1 - ip=$2 - maskbits=$3 - /sbin/ip addr del $ip dev $iface || { - echo "`/bin/date` Failed to del $ip on dev $iface" - exit 1 - } - - # flush our route cache - echo 1 > /proc/sys/net/ipv4/route/flush - ;; - - - ########################################### - # called when ctdbd has finished a recovery - recovered) - ;; - - #################################### - # called when ctdbd is shutting down - shutdown) - ;; - - *) - echo "`/bin/date` Invalid ctdb event command $cmd" - exit 1 - ;; esac ####################################### -# call all application specific scripts +# call all application or local scripts [ -d /etc/ctdb/events.d ] && { - /bin/ls /etc/ctdb/events.d | /bin/grep -v '~' | + # only accept scripts of the form NN.name + /bin/ls /etc/ctdb/events.d | /bin/grep '^[0-9]*\.\w*$' | sort -n | while read SCRIPT; do [ -x /etc/ctdb/events.d/$SCRIPT ] && { /etc/ctdb/events.d/$SCRIPT $cmd "$1" "$2" "$3" || exit 1 diff --git a/ctdb/config/events.d/10.interface b/ctdb/config/events.d/10.interface new file mode 100755 index 00000000000..ea28eb70451 --- /dev/null +++ b/ctdb/config/events.d/10.interface @@ -0,0 +1,78 @@ +#!/bin/sh + +################################# +# interface event script for ctdb +# this adds/removes IPs from your +# public interface + +. /etc/ctdb/functions + +cmd="$1" +shift + +case $cmd in + ############################# + # called when ctdbd starts up + startup) + ;; + + + ################################################ + # called when ctdbd wants to claim an IP address + takeip) + if [ $# != 3 ]; then + echo "must supply interface, IP and maskbits" + exit 1 + fi + iface=$1 + ip=$2 + maskbits=$3 + + # we make sure the interface is up first + /sbin/ip link set $iface up || { + echo "`/bin/date` Failed to bringup interface $iface" + exit 1 + } + /sbin/ip addr add $ip/$maskbits dev $iface || { + echo "`/bin/date` Failed to add $ip/$maskbits on dev $iface" + exit 1 + } + + # flush our route cache + echo 1 > /proc/sys/net/ipv4/route/flush + ;; + + + ################################################## + # called when ctdbd wants to release an IP address + releaseip) + if [ $# != 3 ]; then + echo "`/bin/date` must supply interface, IP and maskbits" + exit 1 + fi + iface=$1 + ip=$2 + maskbits=$3 + /sbin/ip addr del $ip dev $iface || { + echo "`/bin/date` Failed to del $ip on dev $iface" + exit 1 + } + + # flush our route cache + echo 1 > /proc/sys/net/ipv4/route/flush + ;; + + + ########################################### + # called when ctdbd has finished a recovery + recovered) + ;; + + #################################### + # called when ctdbd is shutting down + shutdown) + ;; + +esac + +exit 0 diff --git a/ctdb/config/events.d/samba b/ctdb/config/events.d/50.samba old mode 100644 new mode 100755 similarity index 100% rename from ctdb/config/events.d/samba rename to ctdb/config/events.d/50.samba diff --git a/ctdb/config/events.d/nfslock b/ctdb/config/events.d/59.nfslock old mode 100644 new mode 100755 similarity index 93% rename from ctdb/config/events.d/nfslock rename to ctdb/config/events.d/59.nfslock index 72279b27974..b030ab5463d --- a/ctdb/config/events.d/nfslock +++ b/ctdb/config/events.d/59.nfslock @@ -4,8 +4,7 @@ . /etc/ctdb/functions loadconfig nfs -[ -z $CTDB_MANAGES_NFS ] && exit 0 -[ $CTDB_MANAGES_NFS != "yes" ] && exit 0 +[ "$CTDB_MANAGES_NFS" = "yes" ] || exit 0 [ -z "$STATD_SHARED_DIRECTORY" ] && exit 0 diff --git a/ctdb/config/events.d/nfs b/ctdb/config/events.d/60.nfs old mode 100644 new mode 100755 similarity index 91% rename from ctdb/config/events.d/nfs rename to ctdb/config/events.d/60.nfs index 965199661f3..d0e892622e8 --- a/ctdb/config/events.d/nfs +++ b/ctdb/config/events.d/60.nfs @@ -4,8 +4,7 @@ . /etc/ctdb/functions loadconfig nfs -[ -z $CTDB_MANAGES_NFS ] && exit 0 -[ $CTDB_MANAGES_NFS != "yes" ] && exit 0 +[ "$CTDB_MANAGES_NFS" = "yes" ] || exit 0 cmd="$1" shift diff --git a/ctdb/packaging/RPM/ctdb.spec b/ctdb/packaging/RPM/ctdb.spec index ab6a0e3c9e4..500f636566a 100644 --- a/ctdb/packaging/RPM/ctdb.spec +++ b/ctdb/packaging/RPM/ctdb.spec @@ -93,9 +93,10 @@ fi %{_sysconfdir}/ctdb/events %{_sysconfdir}/ctdb/functions -%{_sysconfdir}/ctdb/events.d/samba -%{_sysconfdir}/ctdb/events.d/nfslock -%{_sysconfdir}/ctdb/events.d/nfs +%{_sysconfdir}/ctdb/events.d/10.interface +%{_sysconfdir}/ctdb/events.d/50.samba +%{_sysconfdir}/ctdb/events.d/59.nfslock +%{_sysconfdir}/ctdb/events.d/60.nfs %{_sysconfdir}/ctdb/statd-callout %{_sbindir}/ctdbd %{_bindir}/ctdb diff --git a/ctdb/tools/ctdb_control.c b/ctdb/tools/ctdb_control.c index 6720d511938..bfaa689009c 100644 --- a/ctdb/tools/ctdb_control.c +++ b/ctdb/tools/ctdb_control.c @@ -301,7 +301,7 @@ static int control_status(struct ctdb_context *ctdb, int argc, const char **argv printf("Number of nodes:%d\n", nodemap->num); for(i=0;inum;i++){ - printf("vnn:%d %16s %s%s\n", nodemap->nodes[i].vnn, + printf("vnn:%d %-16s %s%s\n", nodemap->nodes[i].vnn, inet_ntoa(nodemap->nodes[i].sin.sin_addr), nodemap->nodes[i].flags&NODE_FLAGS_CONNECTED? "CONNECTED":"UNAVAILABLE",