mirror of
https://github.com/samba-team/samba.git
synced 2025-03-27 22:50:26 +03:00
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)
This commit is contained in:
parent
5aeae9744e
commit
bb39f0a186
@ -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
|
||||
|
44
ctdb/config/notify.d.README
Executable file
44
ctdb/config/notify.d.README
Executable file
@ -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.
|
@ -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
|
||||
# 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"
|
||||
|
||||
event="$1"
|
||||
shift
|
||||
ok=true
|
||||
|
||||
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?
|
||||
;;
|
||||
for i in "${nd}/"* ; do
|
||||
# Don't run files matching basename
|
||||
case "${i##*/}" in
|
||||
*~|*,|*.rpm*|*.swp|README) continue ;;
|
||||
esac
|
||||
|
||||
setup)
|
||||
# do some extra magic when ctdb has setup itself?
|
||||
;;
|
||||
# Files must be executable
|
||||
[ -x "$i" ] || continue
|
||||
|
||||
init)
|
||||
# do some extra magic when ctdb has started?
|
||||
;;
|
||||
esac
|
||||
# Flag failures
|
||||
"$i" "$1" || ok=false
|
||||
done
|
||||
|
||||
exit 0
|
||||
$ok
|
||||
|
@ -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
|
||||
|
Loading…
x
Reference in New Issue
Block a user