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