ctdb_check_tcp_ports: cope with multiple locations of netcat or nc
authorMichael Adam <obnox@samba.org>
Fri, 30 Jan 2009 15:10:05 +0000 (16:10 +0100)
committerMichael Adam <obnox@samba.org>
Fri, 30 Jan 2009 21:45:39 +0000 (22:45 +0100)
This fixes tcp port monitor events on systems, where netcat or nc
is not found in /usr/bin/, Debian, for instance.

The patch also separates the process of finding the binaries and
calling them, moving the detection outside of the loop over the
ports list.

Michael

config/functions

index 48bcf2529177a2086ea008708e7fd25d16a7a869..ea5f5a07f4389a428cc722086ed79d17a81a975d 100644 (file)
@@ -205,17 +205,33 @@ ctdb_check_tcp_ports() {
   shift
   wait_ports="$*"
   [ -z "$wait_ports" ] && return;
+
+  # check availability of netcat or netstat first
+  NETCAT=""
+  NETSTAT=""
+  if [ -x /usr/bin/netcat ]; then
+      NETCAT=/usr/bin/netcat
+  elif [ -x /bin/netcat ]; then
+      NETCAT=/bin/netcat
+  elif [ -x /usr/bin/nc ]; then
+      NETCAT=/usr/bin/nc
+  elif [ -x /bin/nc ]; then
+      NETCAT=/bin/nc
+  elif [ -x /usr/bin/netstat ]; then
+      NETSTAT=/usr/bin/netstat
+  elif [ -x /bin/netstat ]; then
+      NETSTAT=/bin/netstat
+  fi
+
   for p in $wait_ports; do
       all_ok=1
-      if [ -x /usr/bin/netcat ]; then
-          /usr/bin/netcat -z 127.0.0.1 $p > /dev/null || all_ok=0
-      elif [ -x /usr/bin/nc ]; then
-          /usr/bin/nc -z 127.0.0.1 $p > /dev/null || all_ok=0
-      elif [ -x /usr/bin/netstat ]; then
-          (netstat -a -n | egrep "0.0.0.0:$p .*LISTEN" > /dev/null ) || all_ok=0
-      elif [ -x /bin/netstat ]; then
-          (netstat -a -n | egrep "0.0.0.0:$p .*LISTEN" > /dev/null ) || all_ok=0
+
+      if [ "x${NETCAT}" != "x" ]; then
+          ${NETCAT} -z 127.0.0.1 $p > /dev/null || all_ok=0
+      elif [ "x${NETSTAT}" != "x" ]; then
+          ( ${NETSTAT} -a -n | egrep "0.0.0.0:$p .*LISTEN" > /dev/null ) || all_ok=0
       fi
+
       [ $all_ok -eq 1 ] || {
          echo "ERROR: $service_name tcp port $p is not responding"
          exit 1