source: vendor/current/ctdb/tools/ctdb_diagnostics

Last change on this file was 988, checked in by Silvan Scherrer, 9 years ago

Samba Server: update vendor to version 4.4.3

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