# check a set of tcp ports
# usage: ctdb_check_tcp_ports <ports...>
######################################################
-ctdb_check_tcp_ports() {
+ctdb_check_tcp_ports()
+{
+ _cmd='netstat -l -t -n'
+ _ns=$($_cmd)
+ for _p ; do # process each function argument (port)
+ for _a in '0\.0\.0\.0' '::' ; do
+ _pat="[[:space:]]${_a}:${_p}[[:space:]]+[^[:space:]]+[[:space:]]+LISTEN"
+ if echo "$_ns" | grep -E -q "$_pat" ; then
+ # We matched the port, so process next port
+ continue 2
+ fi
+ done
- for p ; do
- if ! netstat -a -t -n | grep -q "0\.0\.0\.0:$p .*LISTEN" ; then
- if ! netstat -a -t -n | grep -q ":::$p .*LISTEN" ; then
- echo "ERROR: $service_name tcp port $p is not responding"
- return 1
- fi
- fi
+ # We didn't match the port, so flag an error, print some debug
+ cat <<EOF
+ERROR: $service_name tcp port $_p is not responding
+$_cmd shows this output:
+$_ns
+EOF
+ return 1
done
}