3 # Event script for ctdb-specific setup and other things that don't fit
6 [ -n "$CTDB_BASE" ] || \
7 export CTDB_BASE=$(cd -P $(dirname "$0") ; dirname "$PWD")
12 ctdb_setup_service_state_dir "ctdb"
14 ############################################################
18 # Find the best TDB consistency check available.
19 use_tdb_tool_check=false
20 type tdbtool >/dev/null 2>&1 && found_tdbtool=true
21 type tdbdump >/dev/null 2>&1 && found_tdbdump=true
23 if $found_tdbtool && echo "help" | tdbtool | grep -q check ; then
24 use_tdb_tool_check=true
25 elif $found_tdbtool && $found_tdbdump ; then
27 WARNING: The installed 'tdbtool' does not offer the 'check' subcommand.
28 Using 'tdbdump' for database checks.
29 Consider updating 'tdbtool' for better checks!
31 elif $found_tdbdump ; then
33 WARNING: 'tdbtool' is not available.
34 Using 'tdbdump' to check the databases.
35 Consider installing a recent 'tdbtool' for better checks!
39 WARNING: Cannot check databases since neither
40 'tdbdump' nor 'tdbtool check' is available.
41 Consider installing tdbtool or at least tdbdump!
51 if $use_tdb_tool_check ; then
52 # tdbtool always exits with 0 :-(
53 if timeout 10 tdbtool "$_db" check 2>/dev/null |
54 grep -q "Database integrity is OK" ; then
60 timeout 10 tdbdump "$_db" >/dev/null 2>/dev/null
65 check_persistent_databases ()
67 _dir="${CTDB_DBDIR_PERSISTENT:-${CTDB_DBDIR:-${CTDB_VARDIR}}/persistent}"
68 mkdir -p "$_dir" 2>/dev/null
70 [ "${CTDB_MAX_PERSISTENT_CHECK_ERRORS:-0}" = "0" ] || return 0
72 for _db in $(ls "$_dir/"*.tdb.*[0-9] 2>/dev/null) ; do
74 echo "Persistent database $_db is corrupted! CTDB will not start."
80 check_non_persistent_databases ()
82 _dir="${CTDB_DBDIR:-${CTDB_VARDIR}}"
83 mkdir -p "$_dir" 2>/dev/null
85 for _db in $(ls "${_dir}/"*.tdb.*[0-9] 2>/dev/null) ; do
87 _backup="${_db}.$(date +'%Y%m%d.%H%M%S.%N').corrupt"
89 WARNING: database ${_db} is corrupted.
90 Moving to backup ${_backup} for later analysis.
94 # Now remove excess backups
95 ls -td "${_db}."*".corrupt" |
96 tail -n +$((${CTDB_MAX_CORRUPT_DB_BACKUPS:-10} + 1)) |
103 set_ctdb_variables ()
105 # set any tunables from the config file
106 set | sed -n '/^CTDB_SET_/s/=.*//p' |
108 varname="${v#CTDB_SET_}"
109 value=$(eval echo "\$$v")
110 if ctdb setvar $varname $value ; then
111 echo "Set $varname to $value"
113 echo "Invalid configuration: CTDB_SET_${varname}=${value}"
119 ############################################################
125 # make sure we have a blank state directory for the scripts to work with
126 rm -rf "$CTDB_SCRIPT_VARDIR"
127 mkdir -p "$CTDB_SCRIPT_VARDIR" || \
128 die "mkdir -p ${CTDB_SCRIPT_VARDIR} - failed - ${ret}" $?
130 if select_tdb_checker ; then
131 check_persistent_databases || exit $?
132 check_non_persistent_databases
137 # Set any tunables from the config file
138 set_ctdb_variables || \
139 die "Aborting setup due to invalid configuration - fix typos, remove unknown tunables"
143 ctdb attach ctdb.tdb persistent
147 ctdb_standard_event_handler "$@"