1
0
mirror of https://github.com/samba-team/samba.git synced 2025-01-11 05:18:09 +03:00
samba-mirror/ctdb/config/events.d/00.ctdb

63 lines
1.6 KiB
Plaintext
Raw Normal View History

#!/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 : called when an IP address is taken over
# releaseip : called when an IP address is released
# recovered : called when ctdb has finished a recovery event
. $CTDB_BASE/functions
loadconfig
case "$1" in
init)
# make sure we have a blank state directory for the scripts to work with
/bin/rm -rf $CTDB_BASE/state
/bin/mkdir -p $CTDB_BASE/state
# set any tunables from the config file
set | grep ^CTDB_SET_ | cut -d_ -f3- |
while read v; do
varname=`echo $v | cut -d= -f1`
value=`echo $v | cut -d= -f2`
ctdb setvar $varname $value || exit 1
echo "Set $varname to $value"
done || exit 1
;;
monitor)
# We should never enter swap, so SwapTotal == SwapFree.
[ "$CTDB_CHECK_SWAP_IS_NOT_USED" = "yes" ] && {
if [ -n "`grep '^Swap\(Total\|Free\)' /proc/meminfo | uniq -s 10 -u`" ]; then
echo We are swapping:
cat /proc/meminfo
ps auxfww
fi
}
# monitor that we are not running out of memory
[ -z "$CTDB_MONITOR_FREE_MEMORY" ] || {
FREE_MEM=`free -m | grep "buffers/cache" | while read A B C D ;do /bin/echo -n $D ; done`
[ `expr "$FREE_MEM" "<" "$CTDB_MONITOR_FREE_MEMORY"` != "0" ] && {
echo "OOM. Free:$FREE_MEM while CTDB treshold is $CTDB_MONITOR_FREE_MEMORY"
cat /proc/meminfo
ps auxfww
echo m > /proc/sysrq-trigger
ctdb disable
sleep 3
ctdb shutdown
}
}
;;
*)
ctdb_standard_event_handler "$@"
;;
esac
# all OK
exit 0