Codebase list debian-goodies / debian/0.37
Imported Debian version 0.37 Javier Fernandez-Sanguino 12 years ago
3 changed file(s) with 119 addition(s) and 56 deletion(s). Raw diff Collapse all Expand all
160160 sys.exit(0)
161161
162162 # TODO - consider putting this in a --verbose option
163 print "These processes do not seem to han an associated init script to restart them:"
163 print "These processes do not seem to have an associated init script to restart them:"
164164 for package in nonrestartable:
165165 print package.name + ':'
166166 for process in package.processes:
321321 # Notice that if it begins with SYSV or /dev/zero
322322 # it is not a deleted file and the descriptor was popped already
323323 # (see above)
324 # We don't care about log files
325 if f.startswith('/var/log/'):
326 continue
327 # Or about files under temporary locations
328 if f.startswith('/var/run/'):
329 continue
330 # Or about files under /tmp
331 if f.startswith('/tmp/'):
332 continue
333 # Or /dev/zero
334 if f.startswith('/dev/zero'):
335 continue
336 # We care about any other DEL files
324337 if re.compile("DEL").search(f):
325338 return 1
326339 for f in self.links:
0 debian-goodies (0.37) unstable; urgency=low
1
2 * checkrestart:
3 - Do not complain about deleted files in /tmp, /var/run or /var/log
4 when seen as descriptors (Closes: #441529)
5 - Fix typo in checkrestart (Closes: #444473)
6 * network-test:
7 - Include patch provided by Federico Ceratto which adds command
8 line support, allows the setting of a verbosity level and makes
9 it possible to log to syslog based on that level. This patch
10 is useful if the script is run through init, cron or other
11 task-scheduling tool.
12
13 -- Javier Fernandez-Sanguino Pen~a <jfs@debian.org> Sun, 14 Oct 2007 23:01:40 +0200
14
015 debian-goodies (0.36) unstable; urgency=low
116
217 * Exclude /var/run contents from the deleted files check which means
6868 # - Use arpping to detect another host with our same IP address
6969 # - Check other TODOs inline in the code
7070
71 while getopts ":hsv:" Option
72 do
73 case $Option in
74 h ) cat <<- EOF
75 Usage: $0 [-s][-v <num>]
76
77 -s Also log messages to local3 syslog facility
78 -v 0 Silent run
79 -v 1 Show only error messages
80 -v 2 Show error and warning messages
81 -v 3 Fully verbose (default)
82
83 EOF
84 exit 0;;
85 v ) VERB=$OPTARG;;
86 s ) LOG=1;;
87 esac
88 done
7189
7290 # BEGIN configuration
7391 # Configure to your needs, these values will be used when
86104 LC_ALL=C
87105 export PATH LC_ALL
88106
107 # error reporting and logging functions
108 info () {
109 [ "$VERB" -gt 2 ] && echo "INFO: $1"
110 [ "$VERB" -gt 2 ] && [ "$LOG" ] && logger -p local3.info "$0 INFO: $1"
111 }
112
113 warn () {
114 [ "$VERB" -gt 1 ] && echo "WARN: $1"
115 [ "$VERB" -gt 1 ] && [ "$LOG" ] && logger -p local3.warn "$0 WARN: $1"
116 }
117
118 err () {
119 [ "$VERB" -gt 0 ] && echo "ERR: $1" >&2
120 [ "$VERB" -gt 0 ] && [ "$LOG" ] && logger -p local3.err "$0 ERR: $1"
121 }
122
123
89124 # Check if all commands we need are available
90125 # NOTE: if using nslookup add "nslookup dnsutils"
91126 ( echo -e "netstat net-tools\nifconfig net-tools\n\
94129 nc netcat" |
95130 while read cmd package; do
96131 if ! `which $cmd 2>/dev/null >&2`; then
97 echo "$cmd is not available! (please install $package)" >&2
132 err "$cmd is not available! (please install $package)"
98133 exit 1
99134 fi
100135 done ) || exit 1
102137 ( echo -e "ethtool ethtool" |
103138 while read cmd package; do
104139 if ! `which $cmd 2>/dev/null >&2`; then
105 echo "$cmd is not available (consider installing $package)" >&2
140 warn "$cmd is not available (consider installing $package)"
106141 exit 1
107142 fi
108143 done )
114149 # Other needs
115150 # We need /proc/net
116151 if [ ! -d /proc/net ] ; then
117 echo "/proc is not available! Please mount it ('mount -t /proc')" >&2
152 err "/proc is not available! Please mount it ('mount -t /proc')"
118153 exit 1
119154 fi
120155
125160 defaultroutes=`netstat -nr |grep ^0.0.0.0 | wc -l`
126161 if [ -z "$defaultif" ] ; then
127162 defaultif=none
128 echo "WARN: This system does not have a default route"
163 warn "This system does not have a default route"
129164 elif [ "$defaultroutes" -gt 1 ] ; then
130 echo "WARN: This system has more than one default route"
165 warn "This system has more than one default route"
131166 else
132 echo "INFO: This system has exactly one default route"
167 info "This system has exactly one default route"
133168 fi
134169
135170
143178 # Check 127.0.0.1 instead (not everybody uses this IP address however,
144179 # although its the one commonly used)
145180 if ! check_host 127.0.0.1 1; then
146 echo "ERR: Cannot ping localhost (127.0.0.1), loopback is broken in this system"
181 err "Cannot ping localhost (127.0.0.1), loopback is broken in this system"
147182 else
148 echo "ERR: Localhost is not answering but 127.0.0.1, check /etc/hosts and verify localhost points to 127.0.0.1"
183 err "Localhost is not answering but 127.0.0.1, check /etc/hosts and verify localhost points to 127.0.0.1"
149184 fi
150185 else
151 echo "INFO: Loopback interface is working properly"
186 info "Loopback interface is working properly"
152187 fi
153188
154189 else
155 echo "ERR: There is no loopback interface in this system"
190 err "There is no loopback interface in this system"
156191 status=1
157192 fi
158193 status=0
234269 # Print results
235270 if [ $status -ne 0 ] ; then
236271 if [ "$ifname" = "$defaultif" ] ; then
237 echo "ERR: The $ifname interface that is associated with your default route has no link!"
272 err "The $ifname interface that is associated with your default route has no link!"
238273 else
239 echo "WARN: Interface $ifname does not have link"
274 warn "Interface $ifname does not have link"
240275 fi
241276 fi
242277 # Find IP addresses for $ifname
243278 inetaddr=`ip addr show $ifname | grep inet | awk '{print $2}'`
244279 if [ -z "$inetaddr" ] ; then
245 echo "WARN: The $ifname interface does not have an IP address assigned"
280 warn "The $ifname interface does not have an IP address assigned"
246281 status=1
247282 else
248283 # TODO: WARN if more than 2 IP addresses?
249284 echo $inetaddr | while read ipaddr; do
250 echo "INFO: The $ifname interface has IP address $ipaddr assigned"
285 info "The $ifname interface has IP address $ipaddr assigned"
251286 done
252287 fi
253288
261296 # TODO: Check also frames and collisions, to detect faulty cables
262297 # or network devices (cheap hubs)
263298 if [ "$txpkts" -eq 0 ] && [ "$rxpkts" -eq 0 ] ; then
264 echo "ERR: The $ifname interface has not tx or rx any packets. Link down?"
299 err "The $ifname interface has not tx or rx any packets. Link down?"
265300 status=1
266301 elif [ "$txpkts" -eq 0 ]; then
267 echo "WARN: The $ifname interface has not transmitted any packets."
302 warn "The $ifname interface has not transmitted any packets."
268303 elif [ "$rxpkts" -eq 0 ] ; then
269 echo "WARN: The $ifname interface has not received any packets."
270 else
271 echo "INFO: The $ifname interface has tx and rx packets."
304 warn "The $ifname interface has not received any packets."
305 else
306 info "The $ifname interface has tx and rx packets."
272307 fi
273308 # TODO: It should be best if there was a comparison with tx/rx packets.
274309 # a few errors are not uncommon if the card has been running for a long
275310 # time. It would be better if a relative comparison was done (i.e.
276311 # less than 1% ok, more than 20% warning, over 80% major issue, etc.)
277312 if [ "$txerrors" -ne 0 ]; then
278 echo "WARN: The $ifname interface has tx errors."
313 warn "The $ifname interface has tx errors."
279314 fi
280315 if [ "$rxerrors" -ne 0 ]; then
281 echo "WARN: The $ifname interface has rx errors."
316 warn "The $ifname interface has rx errors."
282317 fi
283318 return $status
284319 }
293328 # twice.
294329 if [ -n "`echo $status | grep NO-CARRIER`" ] ; then
295330 if [ "$ifname" = "$defaultif" ] ; then
296 echo "ERR: The $ifname interface that is associated with your default route is down!"
331 err "The $ifname interface that is associated with your default route is down!"
297332 status=1
298333 elif [ "$ifname" = "lo" ] ; then
299 echo "ERR: Your lo interface is down, this might cause issues with local applications (but not necessarily with network connectivity)"
334 err "Your lo interface is down, this might cause issues with local applications (but not necessarily with network connectivity)"
300335 else
301 echo "WARN: The $ifname interface is down"
336 warn "The $ifname interface is down"
302337 fi
303338 else
304339 # Check network routes associated with this interface
305 echo "INFO: The $ifname interface is up"
340 info "The $ifname interface is up"
306341 check_if $ifname
307342 check_netroute $ifname
308343 fi
318353 # For each gw that is not the default one, ping it
319354 if [ "$gw" != "0.0.0.0" ] ; then
320355 if ! check_router $gw ; then
321 echo "ERR: The default route is not available since the default router is unreachable"
356 err "The default route is not available since the default router is unreachable"
322357 fi
323358 fi
324359 done
333368 # see if we have an arp. We use 5 packets since it is in our local network.
334369 ping -n -q -c 5 "$router" >/dev/null 2>&1
335370 if [ "$?" -ne 0 ]; then
336 echo "WARN: Router $router does not answer to ICMP pings"
371 warn "Router $router does not answer to ICMP pings"
337372 # Router does not answer, check arp
338373 routerarp=`arp -n | grep "^$router" | grep -v incomplete`
339374 if [ -z "$routerarp" ] ; then
340 echo "ERR: We cannot retrieve a MAC address for router $router"
375 err "We cannot retrieve a MAC address for router $router"
341376 status=1
342377 fi
343378 fi
344379 if [ "$status" -eq 0 ] ; then
345 echo "INFO: The router $router is reachable"
380 info "The router $router is reachable"
346381 fi
347382 return $status
348383 }
362397 status=0
363398 ping -n -q -c $COUNT "$host" >/dev/null 2>&1
364399 if [ "$?" -ne 0 ]; then
365 echo "WARN: Host $host does not answer to ICMP pings"
366 status=1
367 else
368 echo "INFO: Host $host answers to ICMP pings"
400 warn "Host $host does not answer to ICMP pings"
401 status=1
402 else
403 info "Host $host answers to ICMP pings"
369404 fi
370405 return $status
371406 }
375410 status=1
376411 nsfound=0
377412 nsok=0
378 tempfile=`mktemp -t tmptestnet.XXXXXX` || { echo "ERR: Cannot create temporary file! Aborting! " >&2 ; exit 1; }
413 tempfile=`mktemp -t tmptestnet.XXXXXX` || { err "Cannot create temporary file! Aborting! " ; exit 1; }
379414 trap " [ -f \"$tempfile\" ] && /bin/rm -f -- \"$tempfile\"" 0 1 2 3 13 15
380415 cat /etc/resolv.conf | grep -v ^# | grep nameserver |
381416 awk '/nameserver/ { for (i=2;i<=NF;i++) { print $i ; } }' >$tempfile
382417 for nameserver in `cat $tempfile`; do
383418 nsfound=$(( $nsfound + 1 ))
384 echo "INFO: This system is configured to use nameserver $nameserver"
419 info "This system is configured to use nameserver $nameserver"
385420 check_host $nameserver 5
386421 if check_ns $nameserver ; then
387422 nsok=$(( $nsok +1 ))
394429 /bin/rm -f -- "$tempfile"
395430 trap 0 1 2 3 13 15
396431 if [ "$nsfound" -eq 0 ] ; then
397 echo "ERR: The system does not have any nameserver configured"
432 err "The system does not have any nameserver configured"
398433 else
399434 if [ "$status" -ne 0 ] ; then
400435 if [ "$nsfound" -eq 1 ] ; then
401 echo -e "ERR: There is one nameserver configured for this system but it does not work properly"
436 err "There is one nameserver configured for this system but it does not work properly"
402437 else
403 echo "ERR: There are $nsfound nameservers configured for this system and none of them works properly"
438 err "There are $nsfound nameservers configured for this system and none of them works properly"
404439 fi
405440 else
406441 if [ "$nsfound" -eq 1 ] ; then
407 echo "INFO: The nameserver configured for this system works properly"
442 info "The nameserver configured for this system works properly"
408443 else
409 echo "INFO: There are $nsfound nameservers is configured for this system and $nsok are working properly"
444 info "There are $nsfound nameservers is configured for this system and $nsok are working properly"
410445 fi
411446 fi
412447 fi
424459 # Using dnscheck:
425460 dnscheck=`host -t A $CHECK_HOST $nameserver 2>&1 | tail -1`
426461 if [ -n "`echo $dnscheck |grep NXDOMAIN`" ] ; then
427 echo "ERR: Dns server $nameserver does not resolv properly"
462 err "Dns server $nameserver does not resolv properly"
428463 elif [ -n "`echo $dnscheck | grep \"timed out\"`" ] ; then
429 echo "ERR: Dns server $nameserver is not available"
464 err "Dns server $nameserver is not available"
430465 elif [ -z "`echo $dnscheck | egrep \"$CHECK_RESULT\"`" ] ; then
431 echo "WARN: Dns server $nameserver did not return the expected result for $CHECK_HOST"
432 else
433 echo "INFO: Dns server $nameserver resolved correctly $CHECK_HOST"
466 warn "Dns server $nameserver did not return the expected result for $CHECK_HOST"
467 else
468 info "Dns server $nameserver resolved correctly $CHECK_HOST"
434469 status=0
435470 fi
436471
437472 # Using dlint
438473 # dlint $CHECK_HOST @$nameserver >/dev/null 2>&1
439474 # if [ $? -eq 2 ] ; then
440 # echo "ERR: Dns server $nameserver does not resolv properly"
475 # err "Dns server $nameserver does not resolv properly"
441476 # elif [ $? -ne 0 ]; then
442 # echo "ERR: Unexpected error when testing $nameserver"
477 # err "Unexpected error when testing $nameserver"
443478 # else
444 # echo "INFO: Dns server $nameserver resolved correctly $CHECK_HOST"
479 # info "Dns server $nameserver resolved correctly $CHECK_HOST"
445480 # status=0
446481 # fi
447482
451486 check_conn () {
452487 # Checks network connectivity
453488 if ! check_host $CHECK_WEB_HOST >/dev/null ; then
454 echo "WARN: System does not seem to reach Internet host $CHECK_WEB_HOST through ICMP"
455 else
456 echo "INFO: System can reach Internet host $CHECK_WEB_HOST"
489 warn "System does not seem to reach Internet host $CHECK_WEB_HOST through ICMP"
490 else
491 info "System can reach Internet host $CHECK_WEB_HOST"
457492 fi
458493 status=0
459494 # Check web access, using nc
464499 # fooled by transparent proxies)
465500 echo -e "HEAD / HTTP/1.0\n\n" |nc -w 20 $CHECK_WEB_HOST $CHECK_WEB_PORT >/dev/null 2>&1
466501 if [ $? -ne 0 ] ; then
467 echo "ERR: Cannot access web server at Internet host $CHECK_WEB_HOST"
468 status=1
469 else
470 echo "INFO: System can access web server at Internet host $CHECK_WEB_HOST"
502 err "Cannot access web server at Internet host $CHECK_WEB_HOST"
503 status=1
504 else
505 info "System can access web server at Internet host $CHECK_WEB_HOST"
471506 fi
472507 return $status
473508 }