3 # Event script for ctdb-specific setup and other things that don't fit
6 [ -n "$CTDB_BASE" ] || \
7 CTDB_BASE=$(d=$(dirname "$0") ; cd -P "$d" ; dirname "$PWD")
9 . "${CTDB_BASE}/functions"
13 ############################################################
15 # type is commonly supported and more portable than which(1)
16 # shellcheck disable=SC2039
19 # Find the best TDB consistency check available.
20 use_tdb_tool_check=false
21 type tdbtool >/dev/null 2>&1 && found_tdbtool=true
22 type tdbdump >/dev/null 2>&1 && found_tdbdump=true
24 if $found_tdbtool && echo "help" | tdbtool | grep -q check ; then
25 use_tdb_tool_check=true
26 elif $found_tdbtool && $found_tdbdump ; then
28 WARNING: The installed 'tdbtool' does not offer the 'check' subcommand.
29 Using 'tdbdump' for database checks.
30 Consider updating 'tdbtool' for better checks!
32 elif $found_tdbdump ; then
34 WARNING: 'tdbtool' is not available.
35 Using 'tdbdump' to check the databases.
36 Consider installing a recent 'tdbtool' for better checks!
40 WARNING: Cannot check databases since neither
41 'tdbdump' nor 'tdbtool check' is available.
42 Consider installing tdbtool or at least tdbdump!
52 if $use_tdb_tool_check ; then
53 # tdbtool always exits with 0 :-(
54 if timeout 10 tdbtool "$_db" check 2>/dev/null |
55 grep -q "Database integrity is OK" ; then
61 timeout 10 tdbdump "$_db" >/dev/null 2>/dev/null
66 check_persistent_databases ()
68 _dir="${CTDB_DBDIR_PERSISTENT:-${CTDB_VARDIR}/persistent}"
69 [ -d "$_dir" ] || return 0
71 [ "${CTDB_MAX_PERSISTENT_CHECK_ERRORS:-0}" = "0" ] || return 0
73 for _db in "$_dir/"*.tdb.*[0-9] ; do
74 [ -r "$_db" ] || continue
76 die "Persistent database $_db is corrupted! CTDB will not start."
80 check_non_persistent_databases ()
82 _dir="${CTDB_DBDIR:-${CTDB_VARDIR}}"
83 [ -d "$_dir" ] || return 0
85 for _db in "${_dir}/"*.tdb.*[0-9] ; do
86 [ -r "$_db" ] || continue
88 _backup="${_db}.$(date +'%Y%m%d.%H%M%S.%N').corrupt"
90 WARNING: database ${_db} is corrupted.
91 Moving to backup ${_backup} for later analysis.
95 # Now remove excess backups
96 _max="${CTDB_MAX_CORRUPT_DB_BACKUPS:-10}"
97 _bdb="${_db##*/}" # basename
98 find "$_dir" -name "${_bdb}.*.corrupt" |
100 tail -n +$((_max + 1)) |
106 set_ctdb_variables ()
108 _f="${CTDB_BASE}/ctdb.tunables"
109 if [ ! -r "$_f" ] ; then
113 while IFS="=" read _var _val ; do
118 if $CTDB setvar "$_var" "$_val" ; then
119 echo "Set $_var to $_val"
121 echo "Invalid tunable: ${_var}=${_val}"
127 ############################################################
133 # make sure we have a blank state directory for the scripts to work with
134 rm -rf "$CTDB_SCRIPT_VARDIR"
135 mkdir -p "$CTDB_SCRIPT_VARDIR" || \
136 die "mkdir -p ${CTDB_SCRIPT_VARDIR} - failed - $?" $?
138 if select_tdb_checker ; then
139 check_persistent_databases || exit $?
140 check_non_persistent_databases
145 # Set any tunables from the config file
146 set_ctdb_variables || \
147 die "Aborting setup due to invalid configuration - fix typos, remove unknown tunables"
151 $CTDB attach ctdb.tdb persistent