2 # a script to test the basic setup of a CTDB/Samba install
3 # tridge@samba.org September 2007
4 # martin@meltin.net August 2010
9 Usage: ctdb_diagnostics [OPTION] ...
11 -n <nodes> Comma separated list of nodes to operate on
12 -c Ignore comment lines (starting with '#') in file comparisons
13 -w Ignore whitespace in file comparisons
14 --no-ads Do not use commands that assume an Active Directory Server
20 nodes
=$
(ctdb listnodes
-X | cut
-d'|' -f2)
27 temp
=$
(getopt
-n "ctdb_diagnostics" -o "n:cwh" -l no-ads
,help -- "$@")
29 # No! Checking the exit code afterwards is actually clearer...
30 # shellcheck disable=SC2181
37 -n) nodes
=$
(echo "$2" |
sed -e 's@,@ @g') ; shift 2 ;;
38 -c) diff_opts
="${diff_opts} -I ^#.*" ; shift ;;
39 -w) diff_opts
="${diff_opts} -w" ; shift ;;
40 --no-ads) no_ads
=true
; shift ;;
51 # Use 5s ssh timeout if EXTRA_SSH_OPTS doesn't set a timeout.
52 case "$EXTRA_SSH_OPTS" in
53 *ConnectTimeout
=*) : ;;
55 export EXTRA_SSH_OPTS
="${EXTRA_SSH_OPTS} -o ConnectTimeout=5"
58 # Filter nodes. Remove any nodes we can't contact from $node and add
62 if onnode
"$_i" true
>/dev
/null
2>&1 ; then
63 _nodes
="${_nodes}${_nodes:+ }${_i}"
65 bad_nodes
="${bad_nodes}${bad_nodes:+,}${_i}"
70 nodes_comma
=$
(echo "$nodes" |
sed -e 's@[[:space:]]@,@g')
72 PATH
="$PATH:/sbin:/usr/sbin:/usr/lpp/mmfs/bin"
74 # list of config files that must exist and that we check are the same
76 if [ -d /etc
/sysconfig
] ; then
77 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"
79 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"
82 # list of config files that may exist and should be checked that they
83 # are the same on the nodes
84 CONFIG_FILES_MAY
="/usr/local/etc/ctdb/public_addresses /usr/local/etc/ctdb/static-routes"
89 --------------------------------------------------------------------
90 ctdb_diagnostics starting. This script will gather information about
91 your ctdb cluster. You should send the output of this script along
92 with any ctdb or clustered Samba bug reports.
93 --------------------------------------------------------------------
101 NUM_ERRORS
=$
((NUM_ERRORS
+ 1))
102 echo " ERROR[$NUM_ERRORS]: $msg" >> "$ERRORS"
107 _fdetails
=$
(ls -l "$fname" 2>&1)
108 echo " ================================"
111 sed 's/^/ /' "$fname" 2>&1
112 echo " ================================"
116 echo "running $1 on nodes $nodes_comma"
117 onnode
"$nodes_comma" "hostname; date; $1 2>&1 | sed 's/^/ /'" 2>&1
120 show_and_compare_files
() {
131 onnode
"$n" [ -r "$f" ] ||
{
132 # This function takes a format string
133 # shellcheck disable=SC2059
134 msg
=$
(printf "$fmt" "$f" "$n")
139 fstf
="${tmpdir}/${_bf}.node${n}"
140 onnode
"$n" cat "$f" >"$fstf" 2>&1
142 _fdetails
=$
(onnode
"$n" ls -l "$f" 2>&1)
143 echo " ================================"
144 echo " File (on node $n): $f"
147 echo " ================================"
150 echo "Testing for same config file $f on node $n"
151 tmpf
="${tmpdir}/${_bf}.node${n}"
152 onnode
"$n" cat "$f" >"$tmpf" 2>&1
153 # Intentional multi-word splitting on diff_opts
154 # shellcheck disable=SC2086
155 diff $diff_opts "$fstf" "$tmpf" >/dev
/null
2>&1 ||
{
156 error
"File $f is different on node $n"
157 diff -u $diff_opts "$fstf" "$tmpf"
167 if ! tmpdir
=$
(mktemp
-d) ; then
168 echo "Unable to create a temporary directory"
171 ERRORS
="${tmpdir}/diag_err"
175 Diagnosis started on these nodes:
179 if [ -n "$bad_nodes" ] ; then
182 NOT RUNNING DIAGNOSTICS on these uncontactable nodes:
190 For reference, here is the nodes file on the current node...
193 show_file
/usr
/local
/etc
/ctdb
/nodes
196 --------------------------------------------------------------------
197 Comping critical config files on nodes $nodes_comma
200 # Intentional multi-word splitting on CONFIG_FILES_MUST
201 # shellcheck disable=SC2086
202 show_and_compare_files \
203 "%s is missing on node %d" \
206 # Intentional multi-word splitting on CONFIG_FILES_MAY
207 # shellcheck disable=SC2086
208 show_and_compare_files \
209 "Optional file %s is not present on node %d" \
213 --------------------------------------------------------------------
214 Checking for clock drift
218 t2
=$
(onnode
"$i" date +%s
)
220 if [ "$d" -gt 30 -o "$d" -lt -30 ]; then
221 error
"time on node $i differs by $d seconds"
226 --------------------------------------------------------------------
227 Showing software versions
231 show_all
"rpm -qa | egrep 'samba|ctdb|gpfs'"
233 [ -x /usr
/bin
/dpkg-query
] && {
234 show_all
"/usr/bin/dpkg-query --show 'ctdb'"
235 show_all
"/usr/bin/dpkg-query --show 'samba'"
236 #show_all "/usr/bin/dpkg-query --show 'gpfs'"
241 --------------------------------------------------------------------
242 Showing ctdb status and recent log entries
244 show_all
"ctdb status; ctdb ip"
245 show_all
"ctdb statistics"
246 show_all
"ctdb uptime"
247 show_all
"ctdb listvars"
248 show_all
"ctdb getdbmap"
249 show_all
"ctdb -X getdbmap | awk -F'|' 'NR > 1 {print \$3}' | sort | xargs -n 1 ctdb dbstatistics"
251 echo "Showing log.ctdb"
252 show_all
"test -f /usr/local/var/log/log.ctdb && tail -100 /usr/local/var/log/log.ctdb"
254 show_all
"tail -200 /var/log/messages"
255 show_all
"ls -lRs /usr/local/var/lib/ctdb"
256 show_all
"ls -lRs /usr/local/etc/ctdb"
260 --------------------------------------------------------------------
261 Showing system and process status
269 show_all
"/sbin/lspci"
271 show_all
"cat /proc/partitions"
272 show_all
"cat /proc/cpuinfo"
273 show_all
"cat /proc/scsi/scsi"
274 show_all
"/sbin/ifconfig -a"
275 show_all
"/sbin/ifconfig -a"
276 show_all
"/sbin/ip addr list"
277 show_all
"/sbin/route -n"
278 show_all
"netstat -s"
280 show_all
"crontab -l"
282 show_all
"iptables -L -n"
283 show_all
"iptables -L -n -t nat"
284 show_all
"/usr/sbin/rpcinfo -p"
285 show_all
"/usr/sbin/showmount -a"
286 show_all
"/usr/sbin/showmount -e"
287 show_all
"/usr/sbin/nfsstat -v"
288 [ -x /sbin
/multipath
] && {
289 show_all
"/sbin/multipath -ll"
291 [ -x /sbin
/chkconfig
] && {
292 show_all
"/sbin/chkconfig --list"
294 [ -x /usr
/sbin
/getenforce
] && {
295 show_all
"/usr/sbin/getenforce"
297 [ -d /proc
/net
/bonding
] && {
298 for f
in /proc
/net
/bonding
/*; do
304 --------------------------------------------------------------------
307 show_all
"smbstatus -n -B"
310 echo "Skipping \"net ads testjoin\" as requested"
313 show_all
"net ads testjoin"
315 show_all
"net conf list"
316 show_all
"lsof -n | grep smbd"
317 show_all
"lsof -n | grep ctdbd"
318 show_all
"netstat -tan"
321 echo "Skipping \"net ads info\" as requested"
324 show_all
"net ads info"
327 show_all
"smbclient -U% -L 127.0.0.1"
328 WORKGROUP
=$
(testparm
-s --parameter-name=WORKGROUP
2> /dev
/null
)
329 show_all id
"$WORKGROUP/Administrator"
331 show_all
"wbinfo --online-status"
335 echo "Diagnostics finished with $NUM_ERRORS errors"
337 [ -r "$ERRORS" ] && {