This makes it easier to add notification handlers.
Signed-off-by: Martin Schwenke <martin@meltin.net>
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)
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
--- /dev/null
+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.
# 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
%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
%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