From 8daa83a594a2e98f39d764422bfbdbc62c9efd44 Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Fri, 19 Apr 2024 19:20:00 +0200 Subject: Adding upstream version 2:4.20.0+dfsg. Signed-off-by: Daniel Baumann --- ctdb/tools/ctdb_diagnostics | 346 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 346 insertions(+) create mode 100755 ctdb/tools/ctdb_diagnostics (limited to 'ctdb/tools/ctdb_diagnostics') diff --git a/ctdb/tools/ctdb_diagnostics b/ctdb/tools/ctdb_diagnostics new file mode 100755 index 0000000..d16a71c --- /dev/null +++ b/ctdb/tools/ctdb_diagnostics @@ -0,0 +1,346 @@ +#!/bin/sh +# a script to test the basic setup of a CTDB/Samba install +# tridge@samba.org September 2007 +# martin@meltin.net August 2010 + +usage () +{ + cat >&2 < Comma separated list of nodes to operate on + -c Ignore comment lines (starting with '#') in file comparisons + -w Ignore whitespace in file comparisons + --no-ads Do not use commands that assume an Active Directory Server +EOF + exit 1 + +} + +nodes=$(ctdb listnodes -X | cut -d'|' -f2) +bad_nodes="" +diff_opts= +no_ads=false + +parse_options () +{ + temp=$(getopt -n "ctdb_diagnostics" -o "n:cwh" -l no-ads,help -- "$@") + + # No! Checking the exit code afterwards is actually clearer... + # shellcheck disable=SC2181 + [ $? -eq 0 ] || usage + + eval set -- "$temp" + + while true ; do + case "$1" in + -n) nodes=$(echo "$2" | sed -e 's@,@ @g') ; shift 2 ;; + -c) diff_opts="${diff_opts} -I ^#.*" ; shift ;; + -w) diff_opts="${diff_opts} -w" ; shift ;; + --no-ads) no_ads=true ; shift ;; + --) shift ; break ;; + -h|--help|*) usage ;; + esac + done + + [ $# -ne 0 ] && usage +} + +parse_options "$@" + +# Use 5s ssh timeout if EXTRA_SSH_OPTS doesn't set a timeout. +case "$EXTRA_SSH_OPTS" in + *ConnectTimeout=*) : ;; + *) + export EXTRA_SSH_OPTS="${EXTRA_SSH_OPTS} -o ConnectTimeout=5" +esac + +# Filter nodes. Remove any nodes we can't contact from $node and add +# them to $bad_nodes. +_nodes="" +for _i in $nodes ; do + if onnode "$_i" true >/dev/null 2>&1 ; then + _nodes="${_nodes}${_nodes:+ }${_i}" + else + bad_nodes="${bad_nodes}${bad_nodes:+,}${_i}" + fi +done +nodes="$_nodes" + +nodes_comma=$(echo "$nodes" | sed -e 's@[[:space:]]@,@g') + +PATH="$PATH:/sbin:/usr/sbin:/usr/lpp/mmfs/bin" + +# list of config files that must exist and that we check are the same +# on the nodes +if [ -d /etc/sysconfig ] ; then + CONFIG_FILES_MUST="/etc/krb5.conf /etc/hosts /usr/local/etc/ctdb/nodes /etc/sysconfig/ctdb /etc/resolv.conf /etc/nsswitch.conf /etc/sysctl.conf /etc/samba/smb.conf /etc/fstab /etc/multipath.conf /etc/pam.d/system-auth /etc/sysconfig/nfs /etc/exports /etc/vsftpd/vsftpd.conf" +else + CONFIG_FILES_MUST="/etc/krb5.conf /etc/hosts /usr/local/etc/ctdb/nodes /etc/default/ctdb /etc/resolv.conf /etc/nsswitch.conf /etc/sysctl.conf /etc/samba/smb.conf /etc/fstab /etc/multipath.conf /etc/pam.d/system-auth /etc/default/nfs /etc/exports /etc/vsftpd/vsftpd.conf" +fi + +# list of config files that may exist and should be checked that they +# are the same on the nodes +CONFIG_FILES_MAY="/usr/local/etc/ctdb/public_addresses /usr/local/etc/ctdb/static-routes" + +exec 2>&1 + +cat <> "$ERRORS" +} + +show_file() { + fname="$1" + _fdetails=$(ls -l "$fname" 2>&1) + echo " ================================" + echo " File: $fname" + echo " $_fdetails" + sed 's/^/ /' "$fname" 2>&1 + echo " ================================" +} + +show_all() { + echo "running $1 on nodes $nodes_comma" + onnode "$nodes_comma" "hostname; date; $1 2>&1 | sed 's/^/ /'" 2>&1 +} + +show_and_compare_files () { + + fmt="$1" ; shift + + for f ; do + _bf=$(basename "$f") + first=true + + for n in $nodes ; do + + if $first ; then + onnode "$n" [ -r "$f" ] || { + # This function takes a format string + # shellcheck disable=SC2059 + msg=$(printf "$fmt" "$f" "$n") + error "$msg" + continue 2; + } + + fstf="${tmpdir}/${_bf}.node${n}" + onnode "$n" cat "$f" >"$fstf" 2>&1 + + _fdetails=$(onnode "$n" ls -l "$f" 2>&1) + echo " ================================" + echo " File (on node $n): $f" + echo " $_fdetails" + sed 's/^/ /' "$fstf" + echo " ================================" + first=false + else + echo "Testing for same config file $f on node $n" + tmpf="${tmpdir}/${_bf}.node${n}" + onnode "$n" cat "$f" >"$tmpf" 2>&1 + # Intentional multi-word splitting on diff_opts + # shellcheck disable=SC2086 + diff $diff_opts "$fstf" "$tmpf" >/dev/null 2>&1 || { + error "File $f is different on node $n" + diff -u $diff_opts "$fstf" "$tmpf" + } + rm -f "$tmpf" + fi + done + + rm -f "$fstf" + done +} + +if ! tmpdir=$(mktemp -d) ; then + echo "Unable to create a temporary directory" + exit 1 +fi +ERRORS="${tmpdir}/diag_err" +NUM_ERRORS=0 + +cat < 1 {print \$3}' | sort | xargs -n 1 ctdb dbstatistics" + +echo "Showing log.ctdb" +show_all "test -f /usr/local/var/log/log.ctdb && tail -100 /usr/local/var/log/log.ctdb" + +show_all "tail -200 /var/log/messages" +show_all "ls -lRs /usr/local/var/lib/ctdb" +show_all "ls -lRs /usr/local/etc/ctdb" + + +cat < /dev/null) +show_all id "$WORKGROUP/Administrator" +show_all "wbinfo -p" +show_all "wbinfo --online-status" +show_all "smbd -b" + +date +echo "Diagnostics finished with $NUM_ERRORS errors" + +[ -r "$ERRORS" ] && { + cat "$ERRORS" + rm -f "$ERRORS" +} + +rm -rf "$tmpdir" + +exit $NUM_ERRORS + -- cgit v1.2.3