[SCM] CTDB repository - branch 1.2 updated - ctdb-1.9.1-476-ge73bcd3

Ronnie Sahlberg sahlberg at samba.org
Mon Aug 22 19:01:11 MDT 2011


The branch, 1.2 has been updated
       via  e73bcd36a477dfab5e0555fb3585d35bbab162f1 (commit)
       via  5aa5a22a797d3bd312dd35b2bf8fbc98e45edf22 (commit)
       via  bafe7b665755356ea2be2d2980cc8ca14c34d099 (commit)
       via  536ce3ead42e1b519888003b311d4eb2a61a8daa (commit)
      from  d84c171a9ca18f9fe1f71a3fd329e77a012a1481 (commit)

http://gitweb.samba.org/?p=ctdb.git;a=shortlog;h=1.2


- Log -----------------------------------------------------------------
commit e73bcd36a477dfab5e0555fb3585d35bbab162f1
Author: Martin Schwenke <martin at meltin.net>
Date:   Fri Aug 19 14:20:58 2011 +1000

    Eventscripts - ctdb_check_tcp_ports() bug fix.
    
    Signed-off-by: Martin Schwenke <martin at meltin.net>

commit 5aa5a22a797d3bd312dd35b2bf8fbc98e45edf22
Author: Martin Schwenke <martin at meltin.net>
Date:   Fri Aug 19 13:55:55 2011 +1000

    Eventscripts - fix debugging buglet in ctdb_check_tcp_ports_ctdb()
    
    Signed-off-by: Martin Schwenke <martin at meltin.net>

commit bafe7b665755356ea2be2d2980cc8ca14c34d099
Author: Martin Schwenke <martin at meltin.net>
Date:   Wed Aug 17 14:02:45 2011 +1000

    Eventscripts - new default TCP port checker using "ctdb checktcpport"
    
    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 at meltin.net>

commit 536ce3ead42e1b519888003b311d4eb2a61a8daa
Author: Martin Schwenke <martin at meltin.net>
Date:   Wed Aug 17 12:12:20 2011 +1000

    Eventscripts - generalise TCP port checking plus new nmap-based checker
    
    Split the netstat-specific parts of ctdb_check_tcp_ports() into new
    function ctdb_check_tcp_ports_netstat().
    
    Implement new ctdb_check_tcp_ports_nmap() function that uses
    "nmap -PS" to check if the desired ports are listening.
    
    ctdb_check_ctdb_ports() now uses new configuration variable
    CTDB_TCP_PORT_CHECKERS to decide which port checkers to try.  Default
    value is currently "nmap netstat".  If nmap is not found then this
    will fall back to netstat.  This indicates that either nmap should be
    installed or the default value of CTDB_TCP_PORT_CHECKERS should be
    changed (in a configuration file) to avoid trying to use nmap.
    
    Signed-off-by: Martin Schwenke <martin at meltin.net>

-----------------------------------------------------------------------

Summary of changes:
 config/functions |  137 ++++++++++++++++++++++++++++++++++++++++++++++++------
 1 files changed, 123 insertions(+), 14 deletions(-)


Changeset truncated at 500 lines:

diff --git a/config/functions b/config/functions
index 1f50e70..8d2e48c 100755
--- a/config/functions
+++ b/config/functions
@@ -210,10 +210,61 @@ ctdb_check_tcp_init ()
 
 ctdb_check_tcp_ports()
 {
-    _ctdb_check_tcp_common
+    if [ -z "$1" ] ; then
+	echo "INTERNAL ERROR: ctdb_check_tcp_ports - no ports specified"
+	exit 1
+    fi
+
+    # Set default value for CTDB_TCP_PORT_CHECKS if unset.
+    # 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:=ctdb nmap netstat}
+
+    for _c in $CTDB_TCP_PORT_CHECKERS ; do
+	ctdb_check_tcp_ports_$_c "$@"
+	case "$?" in
+	    0)
+		_ctdb_check_tcp_common
+		rm -f "$_ctdb_service_started_file"
+		return 0
+		;;
+	    1)
+		_ctdb_check_tcp_common
+		if [ ! -f "$_ctdb_service_started_file" ] ; then
+		    echo "ERROR: $service_name tcp port $_p is not responding"
+		    cat <<EOF
+$ctdb_check_tcp_ports_debug
+EOF
+		else
+		    echo "INFO: $service_name tcp port $_p is not responding"
+		fi
 
+		return 1
+		;;
+	    127)
+		: # Not implemented
+		;;
+	    *)
+		
+	esac
+    done
+
+    echo "INTERNAL ERROR: ctdb_check_ports - no working checkers in CTDB_TCP_PORT_CHECKERS=\"$CTDB_TCP_PORT_CHECKERS\""
+
+    return 127
+}
+
+ctdb_check_tcp_ports_netstat ()
+{
     _cmd='netstat -l -t -n'
-    _ns=$($_cmd)
+    _ns=$($_cmd 2>&1)
+    if [ $? -eq 127 ] ; then
+	# netstat probably not installed - unlikely?
+	ctdb_check_tcp_ports_debug="$_ns"
+	return 127
+    fi
+
     for _p ; do  # process each function argument (port)
 	for _a in '0\.0\.0\.0' '::' ; do
 	    _pat="[[:space:]]${_a}:${_p}[[:space:]]+[^[:space:]]+[[:space:]]+LISTEN"
@@ -223,21 +274,79 @@ ctdb_check_tcp_ports()
 	    fi
 	done
 
-	# We didn't match the port, so flag an error, print some debug
-	if [ ! -f "$_ctdb_service_started_file" ] ; then
-	    cat <<EOF
-ERROR: $service_name tcp port $_p is not responding
-$_cmd shows this output:
-$_ns
-EOF
-	else
-	    echo "INFO: $service_name tcp port $_p is not responding"
-	fi
-
+	# We didn't match the port, so flag an error.
+	ctdb_check_tcp_ports_debug="$_cmd shows this output:
+$_ns"
 	return 1
     done
 
-    rm -f "$_ctdb_service_started_file"
+    return 0
+}
+
+ctdb_check_tcp_ports_nmap ()
+{
+    # nmap wants a comma-separated list of ports
+    _ports=""
+    for _p ; do
+	_ports="${_ports}${_ports:+,}${_p}"
+    done
+
+    _cmd="nmap -n -oG - -PS 127.0.0.1 -p $_ports"
+
+    _nmap_out=$($_cmd 2>&1)
+    if [ $? -eq 127 ] ; then
+	# nmap probably not installed
+	ctdb_check_tcp_ports_debug="$_nmap_out"
+	return 127
+    fi
+
+    # get the port-related output
+    _port_info=$(echo "$_nmap_out" | sed -n -r -e 's@^.*Ports:[[:space:]]@@p')
+
+    for _p ; do
+	# looking for something like this:
+	#  445/open/tcp//microsoft-ds///
+	# possibly followed by a comma
+	_t="$_p/open/tcp//"
+	case "$_port_info" in
+	    # The info we're after must be either at the beginning of
+	    # the string or it must follow a space.
+            $_t*|*\ $_t*) : ;;
+	    *)
+		# Nope, flag an error...
+		ctdb_check_tcp_ports_debug="$_cmd shows this output:
+$_nmap_out"
+		return 1
+	esac
+    done
+
+    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)
+	_ret=$?
+	case "$_ret" 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 $_ret) with output:
+$_out"
+		# assume not implemented
+		return 127
+	esac
+    done
 
     return 0
 }


-- 
CTDB repository


More information about the samba-cvs mailing list