Debian Codegraph @

ctdb/tools/ctdb_diagnostics

raw
1 #!/bin/sh
2 # a script to test the basic setup of a CTDB/Samba install
3 # [email protected] September 2007
4 # [email protected] August 2010
5
6 usage()
7 {
8 cat >&2 <<EOF
9 Usage: ctdb_diagnostics [OPTION] ...
10 options:
11 -n <nodes> Comma separated list of nodes to operate on
12 -c Ignore comment lines (starting with '#') in file comparisons
13 -l Run in local mode
14 -w Ignore whitespace in file comparisons
15 --no-ads Do not use commands that assume an Active Directory Server
16 EOF
17 exit 1
18
19 }
20
21 nodes=$(ctdb listnodes -X | cut -d'|' -f2)
22 local_mode=false
23 bad_nodes=""
24 diff_opts=
25 no_ads=false
26
27 parse_options()
28 {
29 temp=$(getopt -n "ctdb_diagnostics" -o "n:clwh" -l no-ads,help -- "$@")
30
31 # No! Checking the exit code afterwards is actually clearer...
32 # shellcheck disable=SC2181
33 [ $? -eq 0 ] || usage
34
35 eval set -- "$temp"
36
37 while true; do
38 case "$1" in
39 -n)
40 nodes=$(echo "$2" | sed -e 's@,@ @g')
41 shift 2
42 ;;
43 -c)
44 diff_opts="${diff_opts} -I ^#.*"
45 shift
46 ;;
47 -l)
48 local_mode=true
49 shift
50 ;;
51 -w)
52 diff_opts="${diff_opts} -w"
53 shift
54 ;;
55 --no-ads)
56 no_ads=true
57 shift
58 ;;
59 --)
60 shift
61 break
62 ;;
63 -h | --help | *) usage ;;
64 esac
65 done
66
67 [ $# -ne 0 ] && usage
68 }
69
70 parse_options "$@"
71
72 # Use 5s ssh timeout if EXTRA_SSH_OPTS doesn't set a timeout.
73 case "$EXTRA_SSH_OPTS" in
74 *ConnectTimeout=*) : ;;
75 *)
76 export EXTRA_SSH_OPTS="${EXTRA_SSH_OPTS} -o ConnectTimeout=5"
77 ;;
78 esac
79
80 # Filter nodes. Remove any nodes we can't contact from $node and add
81 # them to $bad_nodes.
82
83 _nodes=""
84 if ! $local_mode; then
85 for _i in $nodes; do
86 if onnode "$_i" true >/dev/null 2>&1; then
87 _nodes="${_nodes}${_nodes:+ }${_i}"
88 else
89 bad_nodes="${bad_nodes}${bad_nodes:+,}${_i}"
90 fi
91 done
92 fi
93
94 nodes="$_nodes"
95
96 nodes_comma=$(echo "$nodes" | sed -e 's@[[:space:]]@,@g')
97
98 PATH="$PATH:/sbin:/usr/sbin:/usr/lpp/mmfs/bin"
99
100 # list of config files that must exist and that we check are the same
101 # on the nodes
102 if [ -d /etc/sysconfig ]; then
103 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"
104 else
105 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"
106 fi
107
108 # list of config files that may exist and should be checked that they
109 # are the same on the nodes
110 CONFIG_FILES_MAY="/usr/local/etc/ctdb/public_addresses /usr/local/etc/ctdb/static-routes"
111
112 exec 2>&1
113
114 cat <<EOF
115 --------------------------------------------------------------------
116 ctdb_diagnostics starting. This script will gather information about
117 your ctdb cluster. You should send the output of this script along
118 with any ctdb or clustered Samba bug reports.
119 --------------------------------------------------------------------
120 EOF
121
122 date
123
124 error()
125 {
126 msg="$1"
127 echo "ERROR: $msg"
128 NUM_ERRORS=$((NUM_ERRORS + 1))
129 echo " ERROR[$NUM_ERRORS]: $msg" >>"$ERRORS"
130 }
131
132 show_file()
133 {
134 fname="$1"
135 _fdetails=$(ls -l "$fname" 2>&1)
136 echo " ================================"
137 echo " File: $fname"
138 echo " $_fdetails"
139 sed 's/^/ /' "$fname" 2>&1
140 echo " ================================"
141 }
142
143 show_all()
144 {
145 if $local_mode; then
146 echo "running on local node"
147 hostname
148 date
149 $1 2>&1 | sed 's/^/ /' 2>&1
150 else
151 echo "running $1 on nodes $nodes_comma"
152 onnode "$nodes_comma" "hostname; date; $1 2>&1 | sed 's/^/ /'" 2>&1
153 fi
154 }
155
156 show_and_compare_files()
157 {
158
159 fmt="$1"
160 shift
161
162 for f; do
163 _bf=$(basename "$f")
164 first=true
165
166 for n in $nodes; do
167
168 if $first; then
169 onnode "$n" [ -r "$f" ] || {
170 # This function takes a format string
171 # shellcheck disable=SC2059
172 msg=$(printf "$fmt" "$f" "$n")
173 error "$msg"
174 continue 2
175 }
176
177 fstf="${tmpdir}/${_bf}.node${n}"
178 onnode "$n" cat "$f" >"$fstf" 2>&1
179
180 _fdetails=$(onnode "$n" ls -l "$f" 2>&1)
181 echo " ================================"
182 echo " File (on node $n): $f"
183 echo " $_fdetails"
184 sed 's/^/ /' "$fstf"
185 echo " ================================"
186 first=false
187 else
188 echo "Testing for same config file $f on node $n"
189 tmpf="${tmpdir}/${_bf}.node${n}"
190 onnode "$n" cat "$f" >"$tmpf" 2>&1
191 # Intentional multi-word splitting on diff_opts
192 # shellcheck disable=SC2086
193 diff $diff_opts "$fstf" "$tmpf" >/dev/null 2>&1 || {
194 error "File $f is different on node $n"
195 diff -u $diff_opts "$fstf" "$tmpf"
196 }
197 rm -f "$tmpf"
198 fi
199 done
200
201 rm -f "$fstf"
202 done
203 }
204
205 if ! tmpdir=$(mktemp -d); then
206 echo "Unable to create a temporary directory"
207 exit 1
208 fi
209 ERRORS="${tmpdir}/diag_err"
210 NUM_ERRORS=0
211
212 cat <<EOF
213 Diagnosis started on these nodes:
214 $nodes_comma
215 EOF
216
217 if [ -n "$bad_nodes" ]; then
218 cat <<EOF
219
220 NOT RUNNING DIAGNOSTICS on these uncontactable nodes:
221 $bad_nodes
222 EOF
223
224 fi
225
226 cat <<EOF
227
228 For reference, here is the nodes file on the current node...
229 EOF
230
231 show_file /usr/local/etc/ctdb/nodes
232
233 cat <<EOF
234 --------------------------------------------------------------------
235 Comping critical config files on nodes $nodes_comma
236 EOF
237
238 # Intentional multi-word splitting on CONFIG_FILES_MUST
239 # shellcheck disable=SC2086
240
241 if ! $local_mode; then
242 show_and_compare_files \
243 "%s is missing on node %d" \
244 $CONFIG_FILES_MUST
245 else
246 for f in $CONFIG_FILES_MUST; do
247 show_file $f
248 done
249 fi
250
251 # Intentional multi-word splitting on CONFIG_FILES_MAY
252 # shellcheck disable=SC2086
253 if ! $local_mode; then
254 show_and_compare_files \
255 "Optional file %s is not present on node %d" \
256 $CONFIG_FILES_MAY
257 else
258 for f in $CONFIG_FILES_MAY; do
259 show_file $f
260 done
261 fi
262
263 cat <<EOF
264 --------------------------------------------------------------------
265 Checking for clock drift
266 EOF
267 t=$(date +%s)
268 for i in $nodes; do
269 t2=$(onnode "$i" date +%s)
270 d=$((t2 - t))
271 if [ "$d" -gt 30 ] || [ "$d" -lt -30 ]; then
272 error "time on node $i differs by $d seconds"
273 fi
274 done
275
276 cat <<EOF
277 --------------------------------------------------------------------
278 Showing software versions
279 EOF
280 show_all "uname -a"
281 [ -x /bin/rpm ] && {
282 show_all "rpm -qa | grep -E 'samba|ctdb|gpfs'"
283 }
284 [ -x /usr/bin/dpkg-query ] && {
285 show_all "/usr/bin/dpkg-query --show 'ctdb'"
286 show_all "/usr/bin/dpkg-query --show 'samba'"
287 #show_all "/usr/bin/dpkg-query --show 'gpfs'"
288 }
289
290 cat <<EOF
291 --------------------------------------------------------------------
292 Showing ctdb status and recent log entries
293 EOF
294 show_all "ctdb status; ctdb ip"
295 show_all "ctdb statistics"
296 show_all "ctdb uptime"
297 show_all "ctdb listvars"
298 show_all "ctdb getdbmap"
299 show_all "ctdb -X getdbmap | awk -F'|' 'NR > 1 {print \$3}' | sort | xargs -n 1 ctdb dbstatistics"
300
301 echo "Showing log.ctdb"
302 show_all "test -f /usr/local/var/log/log.ctdb && tail -100 /usr/local/var/log/log.ctdb"
303
304 show_all "tail -200 /var/log/messages"
305 show_all "ls -lRs /usr/local/var/lib/ctdb"
306 show_all "ls -lRs /usr/local/etc/ctdb"
307
308 cat <<EOF
309 --------------------------------------------------------------------
310 Showing system and process status
311 EOF
312 show_all "df"
313 show_all "df -i"
314 show_all "mount"
315 show_all "w"
316 show_all "ps axfwu"
317 show_all "dmesg"
318 show_all "/sbin/lspci"
319 show_all "dmidecode"
320 show_all "cat /proc/partitions"
321 show_all "cat /proc/cpuinfo"
322 show_all "cat /proc/scsi/scsi"
323 show_all "/sbin/ifconfig -a"
324 show_all "/sbin/ifconfig -a"
325 show_all "cat /proc/net/dev"
326 show_all "/sbin/ip addr list"
327 show_all "/sbin/route -n"
328 show_all "ss -s"
329 show_all "free"
330 show_all "crontab -l"
331 show_all "sysctl -a"
332 show_all "iptables -L -n"
333 show_all "iptables -L -n -t nat"
334 show_all "/usr/sbin/rpcinfo -p"
335 show_all "/usr/sbin/showmount -a"
336 show_all "/usr/sbin/showmount -e"
337 show_all "/usr/sbin/nfsstat -v"
338 [ -x /sbin/multipath ] && {
339 show_all "/sbin/multipath -ll"
340 }
341 [ -x /sbin/chkconfig ] && {
342 show_all "/sbin/chkconfig --list"
343 }
344 [ -x /usr/sbin/getenforce ] && {
345 show_all "/usr/sbin/getenforce"
346 }
347 [ -d /proc/net/bonding ] && {
348 for f in /proc/net/bonding/*; do
349 show_all "cat $f"
350 done
351 }
352
353 cat <<EOF
354 --------------------------------------------------------------------
355 Showing Samba status
356 EOF
357 show_all "smbstatus -n -B"
358 if $no_ads; then
359 echo
360 echo "Skipping \"net ads testjoin\" as requested"
361 echo
362 else
363 show_all "net ads testjoin"
364 fi
365 show_all "net conf list"
366 show_all "lsof -n | grep smbd"
367 show_all "lsof -n | grep ctdbd"
368 show_all "netstat -tan"
369 if $no_ads; then
370 echo
371 echo "Skipping \"net ads info\" as requested"
372 echo
373 else
374 show_all "net ads info"
375 fi
376 show_all "date"
377 show_all "smbclient -U% -L 127.0.0.1"
378 WORKGROUP=$(testparm -s --parameter-name=WORKGROUP 2>/dev/null)
379 show_all id "$WORKGROUP/Administrator"
380 show_all "wbinfo -p"
381 show_all "wbinfo --online-status"
382 show_all "smbd -b"
383
384 date
385 echo "Diagnostics finished with $NUM_ERRORS errors"
386
387 [ -r "$ERRORS" ] && {
388 cat "$ERRORS"
389 rm -f "$ERRORS"
390 }
391
392 rm -rf "$tmpdir"
393
394 exit $NUM_ERRORS