2007-05-29 07:01:31 +04:00
#!/bin/sh
2007-06-01 14:54:26 +04:00
############################
# main event script for ctdb
2007-06-04 09:09:03 +04:00
#
# This script is called with one of the following sets of arguments
# startup : called when ctdb starts
# shutdown : called when ctdb shuts down
2007-06-04 17:54:46 +04:00
# 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
2007-05-29 07:01:31 +04:00
2007-09-14 08:14:03 +04:00
. $CTDB_BASE/functions
2009-11-19 07:00:17 +03:00
loadconfig
2007-05-29 07:01:31 +04:00
2010-10-11 19:49:11 +04:00
update_config_from_tdb() {
# Pull optional ctdb configuration data out of config.tdb
2011-06-28 09:39:38 +04:00
PUBLICADDRESSESKEY='public_addresses:node#'`ctdb -t 1 xpnn|sed -e "s/.*://"`
2010-10-11 19:49:11 +04:00
rm -f $CTDB_VARDIR/state/public_addresses
2010-10-28 06:34:33 +04:00
ctdb pfetch config.tdb $PUBLICADDRESSESKEY $CTDB_VARDIR/state/public_addresses 2>/dev/null
2010-10-11 19:49:11 +04:00
[ "$?" = "0" ] && [ `stat --format="%s" /etc/ctdb/state/public_addresses` != "0" ] && [ ! -z "$CTDB_PUBLIC_ADDRESSES" ] && {
diff $CTDB_VARDIR/state/public_addresses $CTDB_PUBLIC_ADDRESSES >/dev/null 2>/dev/null
[ $? = "0" ] || {
echo CTDB public address configuration had been updated.
echo Extracting new configuration from database.
diff $CTDB_VARDIR/state/public_addresses $CTDB_PUBLIC_ADDRESSES
cp $CTDB_VARDIR/state/public_addresses $CTDB_PUBLIC_ADDRESSES
echo Restarting CTDB
service ctdb restart &
}
}
}
2009-12-01 09:43:47 +03:00
case "$1" in
2010-01-19 12:07:14 +03:00
init)
2007-06-04 09:09:03 +04:00
# make sure we have a blank state directory for the scripts to work with
2010-11-19 06:32:28 +03:00
rm -rf $CTDB_VARDIR/state $ctdb_active_dir/*
2011-08-04 11:14:11 +04:00
mkdir -p $CTDB_VARDIR/state || {
2010-02-12 13:24:08 +03:00
ret=$?
2011-08-04 11:14:11 +04:00
echo "mkdir -p $CTDB_VARDIR/state - failed - $ret"
2010-02-12 13:24:08 +03:00
exit $ret
}
;;
2007-06-04 14:05:31 +04:00
2010-02-12 13:24:08 +03:00
setup)
2007-06-04 14:05:31 +04:00
# 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
2008-01-16 14:06:44 +03:00
echo "Set $varname to $value"
2007-10-29 04:34:45 +03:00
done || exit 1
2007-05-30 06:27:58 +04:00
;;
2008-01-10 02:04:03 +03:00
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 05:37:32 +04:00
startup)
2010-10-11 19:49:11 +04:00
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 05:37:32 +04:00
;;
2008-01-10 02:04:03 +03:00
monitor)
2010-02-09 05:16:35 +03:00
# We should never enter swap, so SwapTotal == SwapFree.
2010-02-11 03:32:22 +03:00
[ "$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
}
2010-02-09 05:16:35 +03:00
2010-04-23 02:52:09 +04:00
# warn when we get low on memory
[ -z "$CTDB_MONITOR_FREE_MEMORY_WARN" ] || {
2011-04-13 06:08:09 +04:00
FREE_MEM=`free -m | grep "buffers/cache" | while read A B C D ;do echo -n $D ; done`
2010-04-23 02:52:09 +04:00
[ `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"
}
}
2008-02-21 05:29:28 +03:00
# monitor that we are not running out of memory
[ -z "$CTDB_MONITOR_FREE_MEMORY" ] || {
2011-04-13 06:08:09 +04:00
FREE_MEM=`free -m | grep "buffers/cache" | while read A B C D ;do echo -n $D ; done`
2008-02-21 05:29:28 +03:00
[ `expr "$FREE_MEM" "<" "$CTDB_MONITOR_FREE_MEMORY"` != "0" ] && {
echo "OOM. Free:$FREE_MEM while CTDB treshold is $CTDB_MONITOR_FREE_MEMORY"
2010-02-09 05:16:35 +03:00
cat /proc/meminfo
ps auxfww
echo m > /proc/sysrq-trigger
2008-02-21 05:29:28 +03:00
ctdb disable
sleep 3
ctdb shutdown
}
}
2009-12-01 10:08:57 +03:00
;;
2009-12-01 09:43:47 +03:00
*)
ctdb_standard_event_handler "$@"
;;
2007-05-29 07:01:31 +04:00
esac
2007-06-01 14:54:26 +04:00
# all OK
exit 0