summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMartin Schwenke <martin@meltin.net>2013-05-17 16:42:25 +1000
committerAmitay Isaacs <amitay@gmail.com>2013-05-23 16:18:23 +1000
commitbb39f0a186d091e9ea2b9d7572d87f8313960bb4 (patch)
tree58d43bd4657abbe4c6add71e5f22bde2aefde640
parent5aeae9744e1bb8c8e715b7c3e052d839d0d09ca5 (diff)
downloadsamba-bb39f0a186d091e9ea2b9d7572d87f8313960bb4.tar.gz
samba-bb39f0a186d091e9ea2b9d7572d87f8313960bb4.tar.xz
samba-bb39f0a186d091e9ea2b9d7572d87f8313960bb4.zip
scripts: Rework notify.sh to use notify.d/ directory
This makes it easier to add notification handlers. Signed-off-by: Martin Schwenke <martin@meltin.net> (This used to be ctdb commit d29e9a420b133088bf23a847c8d1dbce56c25eb0)
-rwxr-xr-xctdb/Makefile.in2
-rwxr-xr-xctdb/config/notify.d.README44
-rwxr-xr-xctdb/config/notify.sh66
-rw-r--r--ctdb/packaging/RPM/ctdb.spec.in2
4 files changed, 70 insertions, 44 deletions
diff --git a/ctdb/Makefile.in b/ctdb/Makefile.in
index 86b4870825..80acfd5b94 100755
--- a/ctdb/Makefile.in
+++ b/ctdb/Makefile.in
@@ -319,6 +319,7 @@ install: all manpages $(PMDA_INSTALL)
mkdir -p $(DESTDIR)$(etcdir)/ctdb/events.d
mkdir -p $(DESTDIR)$(etcdir)/ctdb/nfs-rpc-checks.d
mkdir -p $(DESTDIR)$(etcdir)/sudoers.d/
+ mkdir -p $(DESTDIR)$(etcdir)/ctdb/notify.d
mkdir -p $(DESTDIR)$(docdir)/ctdb
${INSTALLCMD} -m 644 ctdb.pc $(DESTDIR)$(libdir)/pkgconfig
${INSTALLCMD} -m 755 bin/ctdb $(DESTDIR)$(bindir)
@@ -376,6 +377,7 @@ install: all manpages $(PMDA_INSTALL)
if [ -f doc/ltdbtool.1.html ];then ${INSTALLCMD} -m 644 doc/ltdbtool.1.html $(DESTDIR)$(docdir)/ctdb; fi
if [ -f doc/ping_pong.1.html ];then ${INSTALLCMD} -m 644 doc/ping_pong.1.html $(DESTDIR)$(docdir)/ctdb; fi
if [ ! -f $(DESTDIR)$(etcdir)/ctdb/notify.sh ];then ${INSTALLCMD} -m 755 config/notify.sh $(DESTDIR)$(etcdir)/ctdb; fi
+ if [ ! -f $(DESTDIR)$(etcdir)/ctdb/notify.d/README ];then ${INSTALLCMD} -m 755 config/notify.d.README $(DESTDIR)$(etcdir)/ctdb/notify.d/README ; fi
${INSTALLCMD} -m 755 config/debug-hung-script.sh $(DESTDIR)$(etcdir)/ctdb
if [ ! -f $(DESTDIR)$(etcdir)/ctdb/ctdb-crash-cleanup.sh ];then ${INSTALLCMD} -m 755 config/ctdb-crash-cleanup.sh $(DESTDIR)$(etcdir)/ctdb; fi
if [ ! -f $(DESTDIR)$(etcdir)/ctdb/gcore_trace.sh ];then ${INSTALLCMD} -m 755 config/gcore_trace.sh $(DESTDIR)$(etcdir)/ctdb; fi
diff --git a/ctdb/config/notify.d.README b/ctdb/config/notify.d.README
new file mode 100755
index 0000000000..ffce7fab2f
--- /dev/null
+++ b/ctdb/config/notify.d.README
@@ -0,0 +1,44 @@
+This directory should contain executable programs to handle CTDB event
+notifications. The first and only argument passed to each program is
+the event, which is one of:
+
+ init, setup, startup, unhealthy, healthy
+
+To use notifications with this directory then you need to set:
+
+ CTDB_NOTIFY_SCRIPT=/etc/ctdb/notify.sh
+
+in your CTDB configuration file.
+
+An example script that sends SNMP traps for unhealthy/healthy might
+look like this:
+
+ #!/bin/sh
+
+ case "$1" in
+ unhealthy)
+ # Send an SNMP trap saying that the node is unhealthy:
+ snmptrap -m ALL -v 1 -c public 10.1.1.105 ctdb \
+ $(hostname) 0 0 $(date +"%s") ctdb.nodeHealth.0 i 1
+ ;;
+ healthy)
+ # Send an SNMP trap saying that the node is healthy again:
+ snmptrap -m ALL -v 1 -c public 10.1.1.105 ctdb \
+ $(hostname) 0 0 $(date +"%s") ctdb.nodeHealth.0 i 0
+ ;;
+ esac
+
+Alternatively, email could be sent:
+
+ #!/bin/sh
+
+ case "$1" in
+ unhealthy)
+ mail -s "$(hostname) is UNHEALTHY" foo@example.com </dev/null >/dev/null 2>&1
+ ;;
+ healthy)
+ mail -s "$(hostname) is HEALTHY" foo@example.com </dev/null >/dev/null 2>&1
+ ;;
+ esac
+
+When adding programs please note the exclusion patterns in notify.sh.
diff --git a/ctdb/config/notify.sh b/ctdb/config/notify.sh
index 8d3eb87f20..dfcb81a551 100755
--- a/ctdb/config/notify.sh
+++ b/ctdb/config/notify.sh
@@ -3,47 +3,25 @@
# This script is activated by setting CTDB_NOTIFY_SCRIPT=/etc/ctdb/notify.sh
# in /etc/sysconfig/ctdb
-# This is script is invoked from ctdb when node UNHEALTHY flag changes.
-# and can be used to send SNMPtraps, email, etc
-# when the status of a node changes
-
-
-event="$1"
-shift
-
-case $event in
- unhealthy)
-#
-# Send an snmptrap that the node is unhealthy :
-# snmptrap -m ALL -v 1 -c public 10.1.1.105 ctdb `hostname` 0 0 `date +"%s"` ctdb.nodeHealth.0 i 1
-#
-# or send an email :
-# mail foo@bar -s "`hostname` is UNHEALTHY" ...
-#
-# or do something else ...
- ;;
- healthy)
-#
-# Send an snmptrap that the node is healthy again :
-# snmptrap -m ALL -v 1 -c public 10.1.1.105 ctdb `hostname` 0 0 `date +"%s"` ctdb.nodeHealth.0 i 0
-#
-# or send an email :
-# mail foo@bar -s "`hostname` is HEALTHY" ...
-#
-# or do something else ...
- ;;
- startup)
- # do some extra magic when ctdb has finished the initial
- # recovery?
- ;;
-
- setup)
- # do some extra magic when ctdb has setup itself?
- ;;
-
- init)
- # do some extra magic when ctdb has started?
- ;;
-esac
-
-exit 0
+# This is script is invoked from ctdb when certain events happen. See
+# /etc/ctdb/notify.d/README for more details.
+
+d=$(dirname $0)
+nd="${d}/notify.d"
+
+ok=true
+
+for i in "${nd}/"* ; do
+ # Don't run files matching basename
+ case "${i##*/}" in
+ *~|*,|*.rpm*|*.swp|README) continue ;;
+ esac
+
+ # Files must be executable
+ [ -x "$i" ] || continue
+
+ # Flag failures
+ "$i" "$1" || ok=false
+done
+
+$ok
diff --git a/ctdb/packaging/RPM/ctdb.spec.in b/ctdb/packaging/RPM/ctdb.spec.in
index 83261c5483..910b59acd3 100644
--- a/ctdb/packaging/RPM/ctdb.spec.in
+++ b/ctdb/packaging/RPM/ctdb.spec.in
@@ -127,6 +127,7 @@ rm -rf $RPM_BUILD_ROOT
%config(noreplace) %{_sysconfdir}/ctdb/gcore_trace.sh
%config(noreplace) %{_sysconfdir}/ctdb/functions
%attr(755,root,root) %{initdir}/ctdb
+%attr(755,root,root) %{_sysconfdir}/ctdb/notify.d
%{_docdir}/ctdb/README
%{_docdir}/ctdb/COPYING
@@ -162,6 +163,7 @@ rm -rf $RPM_BUILD_ROOT
%config(noreplace) %{_sysconfdir}/ctdb/nfs-rpc-checks.d/40.mountd.check
%config(noreplace) %{_sysconfdir}/ctdb/nfs-rpc-checks.d/50.rquotad.check
%{_sysconfdir}/ctdb/statd-callout
+%{_sysconfdir}/ctdb/notify.d/README
%{_sbindir}/ctdbd
%{_bindir}/ctdb
%{_bindir}/smnotify