add an example script that can be called from crontab to cleanup
authorRonnie Sahlberg <ronniesahlberg@gmail.com>
Thu, 22 Apr 2010 04:02:11 +0000 (14:02 +1000)
committerRonnie Sahlberg <ronniesahlberg@gmail.com>
Thu, 22 Apr 2010 04:02:11 +0000 (14:02 +1000)
and release public ip addresses if ctdbd is no longer running

Makefile.in
config/ctdb-crash-cleanup.sh [new file with mode: 0755]
packaging/RPM/ctdb.spec.in

index 0684df3eca65b1dc371e19c3d3e18f50cf2898d2..054c1e098490e2819e821081d2ab10006a04dccd 100755 (executable)
@@ -233,6 +233,7 @@ install: all
        if [ -f doc/ctdbd.1 ];then ${INSTALLCMD} -m 644 doc/ctdbd.1 $(DESTDIR)$(mandir)/man1; fi
        if [ -f doc/onnode.1 ];then ${INSTALLCMD} -m 644 doc/onnode.1 $(DESTDIR)$(mandir)/man1; fi
        if [ ! -f $(DESTDIR)$(etcdir)/ctdb/notify.sh ];then ${INSTALLCMD} -m 755 config/notify.sh $(DESTDIR)$(etcdir)/ctdb; fi
+       if [ ! -f $(DESTDIR)$(etcdir)/ctdb/ctdb-crash-cleanup.sh ];then ${INSTALLCMD} -m 755 config/ctdb-crash-cleanup.sh $(DESTDIR)$(etcdir)/ctdb; fi
 
 test: all
        tests/run_tests.sh
diff --git a/config/ctdb-crash-cleanup.sh b/config/ctdb-crash-cleanup.sh
new file mode 100755 (executable)
index 0000000..ca6a838
--- /dev/null
@@ -0,0 +1,35 @@
+#!/bin/sh
+#
+# This script can be called from a cronjob to automatically drop/release
+# all public ip addresses if CTDBD has crashed or stopped running.
+#
+
+[ -z "$CTDB_BASE" ] && {
+    CTDB_BASE=/etc/ctdb
+}
+
+[ -z "$CTDB_PUBLIC_ADDRESSES" ] && {
+       CTDB_PUBLIC_ADDRESSES=$CTDB_BASE/public_addresses
+}
+
+[ ! -f "$CTDB_PUBLIC_ADDRESSES" ] && {
+       echo "No public addresses file found. Cant cleanup."
+       exit 1
+}
+
+# if ctdb is running, just return
+ctdb status 2>/dev/null && {
+    exit 0
+}
+
+cat "$CTDB_PUBLIC_ADDRESSES" | cut -d/ -f1 | while read _IP; do
+       _IP_HELD=`/sbin/ip addr show | grep "inet $_IP/"`
+       [ -z "$_IP_HELD" ] || {
+               _IFACE=`echo $_IP_HELD | sed -e "s/.*\s//"`
+               _NM=`echo $_IP_HELD | sed -e "s/.*$_IP\///" -e "s/\s.*//"`
+               logger "Removing public address $_IP/$_NM from device $_IFACE"
+               /sbin/ip addr del $_IP/$_NM dev $_IFACE
+       }
+done
+
+
index 15d7a7b740b89abbe02b4e2883e6841d7a805b2a..4e1ef2db30b823acfb77b6e975b20f617aa78234 100644 (file)
@@ -87,6 +87,7 @@ rm -rf $RPM_BUILD_ROOT
 
 %config(noreplace) %{_sysconfdir}/sysconfig/ctdb
 %config(noreplace) %{_sysconfdir}/ctdb/notify.sh
+%config(noreplace) %{_sysconfdir}/ctdb/ctdb-crash-cleanup.sh
 %config(noreplace) %{_sysconfdir}/ctdb/functions
 %attr(755,root,root) %{initdir}/ctdb