1
0
mirror of https://github.com/samba-team/samba.git synced 2025-01-25 06:04:04 +03:00

110 lines
3.0 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
ctdb_setup_service_state_dir "ctdb"
#
update_config_from_tdb() {
# Pull optional ctdb configuration data out of config.tdb
_key="public_addresses:node#$(ctdb -t 1 xpnn|sed -e 's/.*://')"
_t="$service_state_dir/public_addresses"
rm -f "$_t"
if ctdb pfetch config.tdb "$_key" "$_t" 2>/dev/null && \
[ -s "$_t" -a -n "$CTDB_PUBLIC_ADDRESSES"] && \
! cmp -s "$_t" "$CTDB_PUBLIC_ADDRESSES" ; then
echo "CTDB public address configuration has changed."
echo "Extracting new configuration from database."
diff "$_t" "$CTDB_PUBLIC_ADDRESSES"
cp "$_t" "$CTDB_PUBLIC_ADDRESSES"
echo "Restarting CTDB"
service ctdb restart &
fi
}
case "$1" in
init)
# make sure we have a blank state directory for the scripts to work with
rm -rf $CTDB_VARDIR/state
# Look at the pattern - this should not be -rf!!!
rm -f $ctdb_managed_dir/*
mkdir -p $CTDB_VARDIR/state || {
ret=$?
echo "mkdir -p $CTDB_VARDIR/state - failed - $ret"
exit $ret
}
;;
setup)
# 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
;;
Add a configuration database, implemented as a persistent database. This database can be used, as an option, to store the public address assignment instead of editing the /etc/ctdb/public-addresses file manually. This configuration is stored in one record per key, with a key-name of public-addresses:node#<pnn> where <pnn> is the node number. The content of this record is the same syntax as the /etc/ctdb/public-addresses file. When ctdbd starts, if this key exist and contains data. It is extracted from the database and compared with the normal file /etc/ctdb/public-addresses. If the content differs, the config database "wins" and is used to overwrite/update the /etc/ctdb/public-addresses file, after which ctdbd is restarted. The main benefit with this option is that it can be used to update the public address configuration for nodes that are offline/unreachable by updating their configuration in the persistent database. Once the offline node is available again, it will resync its databases with the rest of the cluster, find out that the config has changed, apply the changes and restart ctdbd automatically. The command to store the public address configuration for a node into the persistent database is : ctdb pstore config.tdb public-addresses:node#<pnn> <filename> where <pnn> is the node# we wish to update the config for, and <filename> is a file containing the new content for that nodes public address configuration. (This used to be ctdb commit 292d7435a360efd7f15a7a99f658a605e07c0a81)
2010-08-25 11:37:32 +10:00
startup)
update_config_from_tdb &
Add a configuration database, implemented as a persistent database. This database can be used, as an option, to store the public address assignment instead of editing the /etc/ctdb/public-addresses file manually. This configuration is stored in one record per key, with a key-name of public-addresses:node#<pnn> where <pnn> is the node number. The content of this record is the same syntax as the /etc/ctdb/public-addresses file. When ctdbd starts, if this key exist and contains data. It is extracted from the database and compared with the normal file /etc/ctdb/public-addresses. If the content differs, the config database "wins" and is used to overwrite/update the /etc/ctdb/public-addresses file, after which ctdbd is restarted. The main benefit with this option is that it can be used to update the public address configuration for nodes that are offline/unreachable by updating their configuration in the persistent database. Once the offline node is available again, it will resync its databases with the rest of the cluster, find out that the config has changed, apply the changes and restart ctdbd automatically. The command to store the public address configuration for a node into the persistent database is : ctdb pstore config.tdb public-addresses:node#<pnn> <filename> where <pnn> is the node# we wish to update the config for, and <filename> is a file containing the new content for that nodes public address configuration. (This used to be ctdb commit 292d7435a360efd7f15a7a99f658a605e07c0a81)
2010-08-25 11:37:32 +10:00
;;
monitor)
# Inherit the debug level from ctdbd on each monitor run. If
# there's a more urgent need then override CTDB_CURRENT_DEBUGLEVEL
# using a file in $CTDB_BASE/rc.local.d/.
ctdb_set_current_debuglevel create
# 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
}
# warn when we get low on memory
[ -z "$CTDB_MONITOR_FREE_MEMORY_WARN" ] || {
FREE_MEM=`free -m | grep "buffers/cache" | while read A B C D ;do echo -n $D ; done`
[ `expr "$FREE_MEM" "<" "$CTDB_MONITOR_FREE_MEMORY_WARN"` != "0" ] && {
echo "Running low on memory. Free:$FREE_MEM while CTDB treshold is $CTDB_MONITOR_FREE_MEMORY_WARN"
}
}
# 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 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