Eventscripts - new default TCP port checker using "ctdb checktcpport"
authorMartin Schwenke <martin@meltin.net>
Wed, 17 Aug 2011 04:02:45 +0000 (14:02 +1000)
committerMartin Schwenke <martin@meltin.net>
Fri, 19 Aug 2011 04:08:18 +0000 (14:08 +1000)
New function ctdb_check_tcp_ports_ctdb().  This should be fast... and
is now the default checker.  If it fails in an unexpected way we fall
back to the nmap and netstat checkers.

Signed-off-by: Martin Schwenke <martin@meltin.net>
config/functions

index caede81e2e2209760bd8c84eb92e3c846583c1ff..f82b353e1bac4e57a1f1e4ef1e9ff8ffe0d6aa0e 100755 (executable)
@@ -219,7 +219,7 @@ ctdb_check_tcp_ports()
     # If any of these defaults are unsupported then this variable can
     # be overridden in /etc/sysconfig/ctdb or via a file in
     # /etc/ctdb/rc.local.d/.
-    : ${CTDB_TCP_PORT_CHECKERS:=nmap netstat}
+    : ${CTDB_TCP_PORT_CHECKERS:=ctdb nmap netstat}
 
     for _c in $CTDB_TCP_PORT_CHECKERS ; do
        ctdb_check_tcp_ports_$_c "$@"
@@ -322,6 +322,33 @@ $_nmap_out"
     return 0
 }
 
+# Use the new "ctdb checktcpport" command to check the port.
+# This is very cheap.
+ctdb_check_tcp_ports_ctdb ()
+{
+    for _p ; do  # process each function argument (port)
+       _cmd="ctdb checktcpport $_p"
+       _out=$($_cmd 2>&1)
+       case "$?" in
+           0)
+               ctdb_check_tcp_ports_debug="\"$_cmd\" was able to bind to port"
+               return 1
+               ;;
+           98)
+               # Couldn't bind, something already listening, next port...
+               continue
+               ;;
+           *)
+               ctdb_check_tcp_ports_debug="$_cmd (exited with $?) with output:
+$_out"
+               # assume not implemented
+               return 127
+       esac
+    done
+
+    return 0
+}
+
 ######################################################
 # check a unix socket
 # usage: ctdb_check_unix_socket SERVICE_NAME <socket_path>