3 # Event script for ctdb-specific setup and other things that don't fit
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 for _db
in "$_dir/"*.tdb.
*[0-9]; do
72 [ -r "$_db" ] ||
continue
74 die
"Persistent database $_db is corrupted! CTDB will not start."
78 check_non_persistent_databases
()
80 _dir
="${CTDB_DBDIR:-${CTDB_VARDIR}}"
81 [ -d "$_dir" ] ||
return 0
83 for _db
in "${_dir}/"*.tdb.
*[0-9]; do
84 [ -r "$_db" ] ||
continue
86 _backup
="${_db}.$(date +'%Y%m%d.%H%M%S').corrupt"
88 WARNING: database ${_db} is corrupted.
89 Moving to backup ${_backup} for later analysis.
93 # Now remove excess backups
94 _max
="${CTDB_MAX_CORRUPT_DB_BACKUPS:-10}"
95 _bdb
="${_db##*/}" # basename
96 find "$_dir" -name "${_bdb}.*.corrupt" |
98 tail -n +$
((_max
+ 1)) |
104 ############################################################
110 # make sure we have a blank state directory for the scripts to work with
111 rm -rf "$CTDB_SCRIPT_VARDIR"
112 mkdir
-p "$CTDB_SCRIPT_VARDIR" ||
113 die
"mkdir -p ${CTDB_SCRIPT_VARDIR} - failed - $?" $?
115 # Load/cache database options from configuration file
118 if select_tdb_checker
; then
119 check_persistent_databases ||
exit $?
120 check_non_persistent_databases