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

156 lines
3.5 KiB
Plaintext
Raw Normal View History

#!/bin/sh
# Event script for ctdb-specific setup and other things that don't fit
# elsewhere.
[ -n "$CTDB_BASE" ] || \
export CTDB_BASE=$(cd -P $(dirname "$0") ; dirname "$PWD")
. $CTDB_BASE/functions
loadconfig
ctdb_setup_service_state_dir "ctdb"
############################################################
select_tdb_checker ()
{
# Find the best TDB consistency check available.
use_tdb_tool_check=false
type tdbtool >/dev/null 2>&1 && found_tdbtool=true
type tdbdump >/dev/null 2>&1 && found_tdbdump=true
if $found_tdbtool && echo "help" | tdbtool | grep -q check ; then
use_tdb_tool_check=true
elif $found_tdbtool && $found_tdbdump ; then
cat <<EOF
WARNING: The installed 'tdbtool' does not offer the 'check' subcommand.
Using 'tdbdump' for database checks.
Consider updating 'tdbtool' for better checks!
EOF
elif $found_tdbdump ; then
cat <<EOF
WARNING: 'tdbtool' is not available.
Using 'tdbdump' to check the databases.
Consider installing a recent 'tdbtool' for better checks!
EOF
else
cat <<EOF
WARNING: Cannot check databases since neither
'tdbdump' nor 'tdbtool check' is available.
Consider installing tdbtool or at least tdbdump!
EOF
return 1
fi
}
check_tdb ()
{
_db="$1"
if $use_tdb_tool_check ; then
# tdbtool always exits with 0 :-(
if timeout 10 tdbtool "$_db" check 2>/dev/null |
grep -q "Database integrity is OK" ; then
return 0
else
return 1
fi
else
timeout 10 tdbdump "$_db" >/dev/null 2>/dev/null
return $?
fi
}
check_persistent_databases ()
{
_dir="${CTDB_DBDIR_PERSISTENT:-${CTDB_DBDIR:-${CTDB_VARDIR}}/persistent}"
mkdir -p "$_dir" 2>/dev/null
[ "${CTDB_MAX_PERSISTENT_CHECK_ERRORS:-0}" = "0" ] || return 0
for _db in $(ls "$_dir/"*.tdb.*[0-9] 2>/dev/null) ; do
check_tdb $_db || {
echo "Persistent database $_db is corrupted! CTDB will not start."
return 1
}
done
}
check_non_persistent_databases ()
{
_dir="${CTDB_DBDIR:-${CTDB_VARDIR}}"
mkdir -p "$_dir" 2>/dev/null
for _db in $(ls "${_dir}/"*.tdb.*[0-9] 2>/dev/null) ; do
check_tdb $_db || {
_backup="${_db}.$(date +'%Y%m%d.%H%M%S.%N').corrupt"
cat <<EOF
WARNING: database ${_db} is corrupted.
Moving to backup ${_backup} for later analysis.
EOF
mv "$_db" "$_backup"
# Now remove excess backups
ls -td "${_db}."*".corrupt" |
tail -n +$((${CTDB_MAX_CORRUPT_DB_BACKUPS:-10} + 1)) |
xargs rm -f
}
done
}
set_ctdb_variables ()
{
# set any tunables from the config file
set | sed -n '/^CTDB_SET_/s/=.*//p' |
while read v; do
varname="${v#CTDB_SET_}"
value=$(eval echo "\$$v")
if ctdb setvar $varname $value ; then
echo "Set $varname to $value"
else
echo "Invalid configuration: CTDB_SET_${varname}=${value}"
return 1
fi
done
}
############################################################
ctdb_check_args "$@"
case "$1" in
init)
# make sure we have a blank state directory for the scripts to work with
rm -rf $CTDB_VARDIR/state
mkdir -p $CTDB_VARDIR/state || {
ret=$?
echo "mkdir -p $CTDB_VARDIR/state - failed - $ret"
exit $ret
}
if select_tdb_checker ; then
check_persistent_databases || exit $?
check_non_persistent_databases
fi
;;
setup)
# Set any tunables from the config file
set_ctdb_variables || \
die "Aborting setup due to invalid configuration - fix typos, remove unknown tunables"
;;
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)
ctdb attach ctdb.tdb persistent
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
;;
*)
ctdb_standard_event_handler "$@"
;;
esac
# all OK
exit 0