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>
Wed, 17 Aug 2011 04:02:45 +0000 (14:02 +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 737c8a7e7cfeee6b4b04910362b1851592227a7d..f65690359b303651f5b44aad7d9f615d42836a75 100755 (executable)
@@ -352,7 +352,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 "$@"
@@ -459,6 +459,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>