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