[SCM] CTDB repository - branch master updated - ctdb-2.1-125-ga8ef006

Amitay Isaacs amitay at samba.org
Mon May 6 03:22:56 MDT 2013


The branch, master has been updated
       via  a8ef00608e48a551a334aded206146807aeb4c5a (commit)
       via  bb2cdff77e8ec79e7d319159b9c9848ecfaaa0f1 (commit)
       via  ef2cf75e95ff382c65524a4d77eb00ab8411d2fc (commit)
       via  136abd4604dc68f7c696704bac708bae53cf1940 (commit)
       via  25ef4f655f1efc833deb5e244f9fff461e92f439 (commit)
       via  60a08eb96e1d97aab31e9bd4af01683c650541c2 (commit)
       via  319c1b68d5aa78f82a68febcad233a7c78afc887 (commit)
       via  8514ca56830b30e7f0eb5018632640daaf8ff65d (commit)
       via  a621622903c7ef17764b15293d6ea8df5a53c7e1 (commit)
       via  10e4db8f796d1e3259733180494db3b4bbad291a (commit)
       via  23c0f5f48e3e5a0c1a3254c582299f7893cf0d33 (commit)
       via  3eae161472e6352f7f656851c73dc056f95113eb (commit)
       via  9e25fb261447a196de05937052779b36e75e7215 (commit)
       via  d9e6cb945c5edac9ca6405c9228bf647fab814f5 (commit)
       via  3d0a7d83ddc824961d876fc9afba829c90aef3e7 (commit)
       via  fff88940f71058e4eefd65f50a6701389c005c17 (commit)
       via  27aab8783898a50da8c4bc887b512d8f0c0d842c (commit)
       via  b5802c4735e1c719a5cf9ce69489d5947bd5e8c5 (commit)
       via  e24baac0d2952e86d5ff31235901f06e2f2b2449 (commit)
       via  c2ea72ff565222f9edab408638bd45dbba6e8ff7 (commit)
       via  fd536a26b310b5bf9628da62cca0b425f4a54030 (commit)
       via  9dee4c84273633b9ad82e94dabbf0e6f86edbcef (commit)
       via  c74cc0442eb90d859eae270b59456d28605817c4 (commit)
       via  cd87ba85fc6c375758c7d3dfa8dbd4d8a02074b0 (commit)
      from  c2bb8596a8af6406ef50e53953884df9d6246a96 (commit)

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


- Log -----------------------------------------------------------------
commit a8ef00608e48a551a334aded206146807aeb4c5a
Author: Martin Schwenke <martin at meltin.net>
Date:   Tue Apr 30 15:33:12 2013 +1000

    eventscripts: Remove unused function ctdb_check_counter_limit()
    
    Signed-off-by: Martin Schwenke <martin at meltin.net>

commit bb2cdff77e8ec79e7d319159b9c9848ecfaaa0f1
Author: Martin Schwenke <martin at meltin.net>
Date:   Tue Apr 30 15:23:20 2013 +1000

    eventscripts: Use ctdb_check_counter() instead of ctdb_check_counter_limit()
    
    ctdb_check_counter_limit() can soon be removed...
    
    Signed-off-by: Martin Schwenke <martin at meltin.net>

commit ef2cf75e95ff382c65524a4d77eb00ab8411d2fc
Author: Martin Schwenke <martin at meltin.net>
Date:   Tue Apr 30 15:19:52 2013 +1000

    eventscripts: Might as well try to stat the reclock file first
    
    It is in the background but it still might cause the counter to be
    reset before it is checked.
    
    Signed-off-by: Martin Schwenke <martin at meltin.net>

commit 136abd4604dc68f7c696704bac708bae53cf1940
Author: Martin Schwenke <martin at meltin.net>
Date:   Tue Apr 30 15:16:44 2013 +1000

    eventscripts: Make the early exit in 01.reclock earlier
    
    That way we don't even check the counter...
    
    Signed-off-by: Martin Schwenke <martin at meltin.net>

commit 25ef4f655f1efc833deb5e244f9fff461e92f439
Author: Martin Schwenke <martin at meltin.net>
Date:   Mon May 6 16:23:25 2013 +1000

    eventscripts: Minor cleanups for killtcp/tickle functions
    
    Signed-off-by: Martin Schwenke <martin at meltin.net>

commit 60a08eb96e1d97aab31e9bd4af01683c650541c2
Author: Martin Schwenke <martin at meltin.net>
Date:   Tue Apr 30 11:39:46 2013 +1000

    eventscripts: Tweak the timeout check in kill_tcp_connections()
    
    This has 2 advantages:
    
    1. It uses get_tcp_connections_for_ip() to check for leftover
       connections, instead of custom code.
    
    2. It checks for the timeout condition before sleeping.  The current
       code sleeps and then checks, so wastes a second.
    
    Signed-off-by: Martin Schwenke <martin at meltin.net>

commit 319c1b68d5aa78f82a68febcad233a7c78afc887
Author: Martin Schwenke <martin at meltin.net>
Date:   Tue Apr 30 06:31:30 2013 +1000

    eventscripts: In killtcp/tickle functions, $_failed should be boolean
    
    Signed-off-by: Martin Schwenke <martin at meltin.net>

commit 8514ca56830b30e7f0eb5018632640daaf8ff65d
Author: Martin Schwenke <martin at meltin.net>
Date:   Tue Apr 30 06:27:58 2013 +1000

    eventscripts: Remove unused $_killcount from tickle_tcp_connections()
    
    Signed-off-by: Martin Schwenke <martin at meltin.net>

commit a621622903c7ef17764b15293d6ea8df5a53c7e1
Author: Martin Schwenke <martin at meltin.net>
Date:   Tue Apr 30 06:25:26 2013 +1000

    eventscripts: Refactor connection listing in killtcp and tickle functions
    
    Uses new function get_tcp_connections_for_ip().  This avoids using a
    temporary file and running netstat twice.
    
    Signed-off-by: Martin Schwenke <martin at meltin.net>

commit 10e4db8f796d1e3259733180494db3b4bbad291a
Author: Martin Schwenke <martin at meltin.net>
Date:   Tue Apr 30 06:19:18 2013 +1000

    eventscripts: Reimplement kill_tcp_connections_local_only()
    
    ... using kill_tcp_connections()
    
    Signed-off-by: Martin Schwenke <martin at meltin.net>

commit 23c0f5f48e3e5a0c1a3254c582299f7893cf0d33
Author: Martin Schwenke <martin at meltin.net>
Date:   Tue Apr 30 06:14:01 2013 +1000

    eventscripts: Change handling of one-way kills in kill_tcp_connections()
    
    This change is a no-op.  However, In a subsequent commit we'll merge
    kill_tcp_connections_local_only() with this function.
    
    Signed-off-by: Martin Schwenke <martin at meltin.net>

commit 3eae161472e6352f7f656851c73dc056f95113eb
Author: Martin Schwenke <martin at meltin.net>
Date:   Tue Apr 30 06:05:52 2013 +1000

    eventscripts: Remove unnecessary variables from killtcp/tickle functions
    
    Setting these variables spawns lots of unnecessary processes, which
    would surely slow down these functions on a busy system.
    
    Signed-off-by: Martin Schwenke <martin at meltin.net>

commit 9e25fb261447a196de05937052779b36e75e7215
Author: Martin Schwenke <martin at meltin.net>
Date:   Tue Apr 30 03:54:17 2013 +1000

    eventscripts: Clean up ctdb_check_command()
    
    * Command is now multiple arguments, preserving quoting
    * $service_name no longer printed, no longer an argument
    * Debug output from failed command
    
    Signed-off-by: Martin Schwenke <martin at meltin.net>

commit d9e6cb945c5edac9ca6405c9228bf647fab814f5
Author: Martin Schwenke <martin at meltin.net>
Date:   Tue Apr 30 03:48:51 2013 +1000

    eventscripts; Cleanup up ctdb_check_directories()
    
    The documentation comments are wrong... and remove option
    $service_name argument.
    
    Signed-off-by: Martin Schwenke <martin at meltin.net>

commit 3d0a7d83ddc824961d876fc9afba829c90aef3e7
Author: Martin Schwenke <martin at meltin.net>
Date:   Tue Apr 30 03:45:21 2013 +1000

    eventscripts: Assert that $service_name is set in a few key places
    
    Signed-off-by: Martin Schwenke <martin at meltin.net>

commit fff88940f71058e4eefd65f50a6701389c005c17
Author: Martin Schwenke <martin at meltin.net>
Date:   Tue Apr 30 15:31:27 2013 +1000

    eventscripts: counters default to $script_name if $service_name not set
    
    Signed-off-by: Martin Schwenke <martin at meltin.net>

commit 27aab8783898a50da8c4bc887b512d8f0c0d842c
Author: Martin Schwenke <martin at meltin.net>
Date:   Tue Apr 30 03:32:29 2013 +1000

    eventscripts: Simplify handling of $service name in "managed" functions
    
    Complicated argument handling was introduced to deal with multiple
    services per eventscript.  This was a failure and we split 50.samba.
    
    This simplifies several functions to use global $service_name
    unconditionally instead of having an optional argument.
    
    $service_name is no automatically longer set in the functions file.
    This means it needs to be explicitly set in 13.per_ip_routing because
    this script uses ctdb_service_check_reconfigure().
    
    Eventscript unit test infrastructure needs to set $service_name during
    fake service setup, and policy routing tests need to be updated
    accordingly.
    
    Signed-off-by: Martin Schwenke <martin at meltin.net>

commit b5802c4735e1c719a5cf9ce69489d5947bd5e8c5
Author: Martin Schwenke <martin at meltin.net>
Date:   Tue Apr 30 03:18:01 2013 +1000

    eventscripts: Simplify handling of $service name in start/stop functions
    
    Complicated argument handling was introduced to deal with multiple
    services per eventscript.  This was a failure and we split 50.samba.
    
    This simplifies several functions to use global $service_name
    unconditionally instead of having an optional argument.
    
    Signed-off-by: Martin Schwenke <martin at meltin.net>

commit e24baac0d2952e86d5ff31235901f06e2f2b2449
Author: Martin Schwenke <martin at meltin.net>
Date:   Tue Apr 30 03:13:36 2013 +1000

    eventscripts: Simplify handling of $service name in service_management
    
    Complicated argument handling was introduced to deal with multiple
    services per eventscript.  This was a failure and we split 50.samba.
    
    This simplifies several functions to use global $service_name
    unconditionally instead of having an optional argument.
    
    Signed-off-by: Martin Schwenke <martin at meltin.net>

commit c2ea72ff565222f9edab408638bd45dbba6e8ff7
Author: Martin Schwenke <martin at meltin.net>
Date:   Tue Apr 30 02:59:41 2013 +1000

    eventscripts: Simplify handling of $service name in reconfigure functions
    
    Complicated argument handling was introduced to deal with multiple
    services per eventscript.  This was a failure and we split 50.samba.
    
    This simplifies several functions to use global $service_name
    unconditionally instead of having an optional argument.
    
    Signed-off-by: Martin Schwenke <martin at meltin.net>

commit fd536a26b310b5bf9628da62cca0b425f4a54030
Author: Martin Schwenke <martin at meltin.net>
Date:   Wed Apr 24 17:14:32 2013 +1000

    eventscripts: Remove unused function ctdb_check_counter_equal()
    
    Signed-off-by: Martin Schwenke <martin at meltin.net>

commit 9dee4c84273633b9ad82e94dabbf0e6f86edbcef
Author: Martin Schwenke <martin at meltin.net>
Date:   Tue Apr 23 13:56:15 2013 +1000

    scripts: Fix script_log() regression
    
    5940a2494e9e43a83f2bca098bd04dfc1a8f2e93 makes script_log() always
    pass a message to logger, so script_log() can no longer log stdin.
    
    Put all the tag fu in the actual tag so the message argument is empty
    if no message was passed.
    
    Signed-off-by: Martin Schwenke <martin at meltin.net>

commit c74cc0442eb90d859eae270b59456d28605817c4
Author: Martin Schwenke <martin at meltin.net>
Date:   Tue Apr 23 13:49:28 2013 +1000

    initscript: Look for tdbtool/tdbdump using which, not in fixed locations
    
    Signed-off-by: Martin Schwenke <martin at meltin.net>

commit cd87ba85fc6c375758c7d3dfa8dbd4d8a02074b0
Author: Martin Schwenke <martin at meltin.net>
Date:   Mon Apr 22 14:55:33 2013 +1000

    ctdbd: Log CTDB startup before creating the PID file
    
    Otherwise the messages are in a stupid order...  :-)
    
    Signed-off-by: Martin Schwenke <martin at meltin.net>
    Reported-by: Amitay Isaacs <amitay at gmail.com>

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

Summary of changes:
 config/ctdb.init                             |    8 +-
 config/events.d/01.reclock                   |   35 ++--
 config/events.d/13.per_ip_routing            |    2 +
 config/events.d/40.vsftpd                    |    5 +-
 config/events.d/49.winbind                   |    2 +-
 config/functions                             |  354 +++++++++++---------------
 server/ctdb_daemon.c                         |    2 +-
 tests/eventscripts/13.per_ip_routing.016.sh  |    2 +-
 tests/eventscripts/13.per_ip_routing.017.sh  |    2 +-
 tests/eventscripts/13.per_ip_routing.018.sh  |    2 +-
 tests/eventscripts/13.per_ip_routing.019.sh  |    2 +-
 tests/eventscripts/49.winbind.monitor.102.sh |    2 +-
 tests/eventscripts/scripts/local.sh          |   32 ++-
 13 files changed, 206 insertions(+), 244 deletions(-)


Changeset truncated at 500 lines:

diff --git a/config/ctdb.init b/config/ctdb.init
index a76b763..013e1ae 100755
--- a/config/ctdb.init
+++ b/config/ctdb.init
@@ -130,17 +130,17 @@ select_tdb_checker ()
 {
     # Find the best TDB consistency check available.
     use_tdb_tool_check=false
-    if [ -x /usr/bin/tdbtool ] && \
-	echo "help" | /usr/bin/tdbtool | grep -q check ; then
+    if which tdbtool >/dev/null 2>&1 && \
+	echo "help" | tdbtool | grep -q check ; then
 
 	use_tdb_tool_check=true
-    elif [ -x /usr/bin/tdbtool -a -x /usr/bin/tdbdump ] ; then
+    elif which tdbtool >/dev/null 2>&1 && which tdbdump >/dev/null 2>&1 ; then
 	    do_log <<EOF
 WARNING: The installed 'tdbtool' does not offer the 'check' subcommand.
  Using 'tdbdump' for database checks.
  Consider updating 'tdbtool' for better checks!
 EOF
-    elif [ -x /usr/bin/tdbdump ] ; then
+    elif which tdbdump >/dev/null 2>&1 ; then
 	do_log <<EOF
 WARNING: 'tdbtool' is not available.
  Using 'tdbdump' to check the databases.
diff --git a/config/events.d/01.reclock b/config/events.d/01.reclock
index a3bfc66..ec50989 100755
--- a/config/events.d/01.reclock
+++ b/config/events.d/01.reclock
@@ -15,30 +15,27 @@ case "$1" in
     monitor)
 	RECLOCKFILE=$(ctdb -Y getreclock)
 
+	# Early exit if not using a reclock file
+	[ -n "$RECLOCKFILE" ] || exit 0
+
+	# Try to stat the reclock file as a background process so that
+	# we don't block in case the cluster filesystem is unavailable
+	(
+	    if stat $RECLOCKFILE ; then
+		# We could stat the file, reset the counter
+		ctdb_counter_init
+	    fi
+	) >/dev/null 2>&1 &
+
 	ctdb_counter_incr
-	(ctdb_check_counter_limit 200 >/dev/null 2>&1) || {
-	    echo "Reclock file $RECLOCKFILE\" can not be accessed. Shutting down."
+	if ! ctdb_check_counter "quiet" -ge 200 ; then
+	    echo "Reclock file \"$RECLOCKFILE\" can not be accessed. Shutting down."
 	    df
 	    sleep 1
 	    ctdb shutdown
-	}
-
-	[ -z "$RECLOCKFILE" ] && {
-	    # we are not using a reclock file
-	    ctdb_counter_init
-	    exit 0
-	}
-
-	# try stat the reclock file as a background process
-	# so that we dont block in case the cluster filesystem is unavailable
-	(
-	    stat $RECLOCKFILE && {
-		# we could stat the file, reset the counter
-		ctdb_counter_init
-	    }
-	) >/dev/null 2>/dev/null &
+	fi
 
-	ctdb_check_counter_limit 3 quiet
+	ctdb_check_counter "error" -gt 3
 	;;
 
     *)
diff --git a/config/events.d/13.per_ip_routing b/config/events.d/13.per_ip_routing
index fe97ffc..4b13546 100755
--- a/config/events.d/13.per_ip_routing
+++ b/config/events.d/13.per_ip_routing
@@ -6,6 +6,8 @@
 . $CTDB_BASE/functions
 loadconfig
 
+service_name=per_ip_routing
+
 # Do nothing if unconfigured 
 [ -n "$CTDB_PER_IP_ROUTING_CONF" ] || exit 0
 
diff --git a/config/events.d/40.vsftpd b/config/events.d/40.vsftpd
index 25964b8..92a0e99 100755
--- a/config/events.d/40.vsftpd
+++ b/config/events.d/40.vsftpd
@@ -53,8 +53,9 @@ case "$1" in
 		ctdb_counter_init
 	    else
 		ctdb_counter_incr
-		ctdb_check_counter_limit
-		exit 0 # only count 1 failure per monitor event
+		ctdb_check_counter
+		ctdb_check_counter "quiet" -ge 1 || \
+		    echo "WARNING: vsftpd not listening but less than $service_fail_limit consecutive failures, not unhealthy yet" 
 	    fi
 	fi	
 	;;
diff --git a/config/events.d/49.winbind b/config/events.d/49.winbind
index d0a154d..ef4eb3f 100755
--- a/config/events.d/49.winbind
+++ b/config/events.d/49.winbind
@@ -54,7 +54,7 @@ case "$1" in
 	;;
 
      monitor)
-	ctdb_check_command "winbind" "wbinfo -p"
+	ctdb_check_command wbinfo -p
 	;;
 
      takeip|releaseip)
diff --git a/config/functions b/config/functions
index b4450c3..3572a00 100755
--- a/config/functions
+++ b/config/functions
@@ -83,7 +83,7 @@ script_log ()
     esac
 
     if $_using_syslog ; then
-	logger -t "ctdbd" "${_tag}: $*"
+	logger -t "ctdbd: ${_tag}" $*
     else
 	{
 	    if [ -n "$*" ] ; then
@@ -349,11 +349,19 @@ $ctdb_check_rpc_out"
 }
 
 ######################################################
+# Ensure $service_name is set
+assert_service_name ()
+{
+    [ -n "$service_name" ] || die "INTERNAL ERROR: \$service_name not set"
+}
+
+######################################################
 # check a set of directories is available
 # return 1 on a missing directory
-# usage: ctdb_check_directories_probe SERVICE_NAME <directories...>
+# directories are read from stdin
 ######################################################
-ctdb_check_directories_probe() {
+ctdb_check_directories_probe()
+{
     while IFS="" read d ; do
 	case "$d" in
 	    *%*)
@@ -367,12 +375,12 @@ ctdb_check_directories_probe() {
 
 ######################################################
 # check a set of directories is available
-# usage: ctdb_check_directories SERVICE_NAME <directories...>
+# directories are read from stdin
 ######################################################
-ctdb_check_directories() {
-    n="${1:-${service_name}}"
+ctdb_check_directories()
+{
     ctdb_check_directories_probe || {
-	echo "ERROR: $n directory \"$d\" not available"
+	echo "ERROR: $service_name directory \"$d\" not available"
 	exit 1
     }
 }
@@ -388,6 +396,7 @@ ctdb_check_directories() {
 # message if a port check fails.
 _ctdb_check_tcp_common ()
 {
+    assert_service_name
     _ctdb_service_started_file="$ctdb_fail_dir/$service_name.started"
 }
 
@@ -561,143 +570,118 @@ ctdb_check_unix_socket() {
 
 ######################################################
 # check a command returns zero status
-# usage: ctdb_check_command SERVICE_NAME <command>
+# usage: ctdb_check_command <command>
 ######################################################
-ctdb_check_command() {
-  service_name="$1"
-  wait_cmd="$2"
-  [ -z "$wait_cmd" ] && return;
-  $wait_cmd > /dev/null 2>&1 || {
-      echo "ERROR: $service_name - $wait_cmd returned error"
-      exit 1
-  }
+ctdb_check_command ()
+{
+    _out=$("$@" 2>&1) || {
+	echo "ERROR: $* returned error"
+	echo "$_out" | debug
+	exit 1
+    }
 }
 
 ################################################
 # kill off any TCP connections with the given IP
 ################################################
-kill_tcp_connections() {
-    _IP="$1"    
-    _failed=0
-
-    _killcount=0
-    connfile="$CTDB_VARDIR/state/connections.$_IP"
-    mkdir -p "${connfile%/*}" # dirname
-    netstat -tn |egrep "^tcp.*[[:space:]]+$_IP:.*ESTABLISHED" | awk '{print $4" "$5}' > $connfile
-    netstat -tn |egrep "^tcp.*[[:space:]]+::ffff:$_IP:.*ESTABLISHED" | awk '{print $4" "$5}' >> $connfile
-
-    while read dest src; do
-	srcip=`echo $src | sed -e "s/:[^:]*$//"`
-	srcport=`echo $src | sed -e "s/^.*://"`
-	destip=`echo $dest | sed -e "s/:[^:]*$//"`
-	destport=`echo $dest | sed -e "s/^.*://"`
-	echo "Killing TCP connection $srcip:$srcport $destip:$destport"
-	ctdb killtcp $srcip:$srcport $destip:$destport >/dev/null 2>&1 || _failed=1
-	case $destport in
-	  # we only do one-way killtcp for CIFS
-	  139|445) : ;;
-	  # for all others we do 2-way
-	  *) 
-	  	ctdb killtcp $destip:$destport $srcip:$srcport >/dev/null 2>&1 || _failed=1
-		;;
-	esac
-	_killcount=`expr $_killcount + 1`
-     done < $connfile
-    rm -f $connfile
+kill_tcp_connections ()
+{
+    _ip="$1"
 
-    [ $_failed = 0 ] || {
-	echo "Failed to send killtcp control"
-	return;
-    }
-    [ $_killcount -gt 0 ] || {
-	return;
+    _oneway=false
+    if [ "$2" = "oneway" ] ; then
+	_oneway=true
+    fi
+
+    get_tcp_connections_for_ip "$_ip" | {
+	_killcount=0
+	_failed=false
+
+	while read dest src; do
+	    echo "Killing TCP connection $src $dest"
+	    ctdb killtcp $src $dest >/dev/null 2>&1 || _failed=true
+	    _destport="${dest##*:}"
+	    __oneway=$_oneway
+	    case $_destport in
+		# we only do one-way killtcp for CIFS
+		139|445) __oneway=true ;;
+	    esac
+	    if ! $__oneway ; then
+		ctdb killtcp $dest $src >/dev/null 2>&1 || _failed=true
+	    fi
+
+	    _killcount=$(($_killcount + 1))
+	done
+
+	if $_failed ; then
+	    echo "Failed to send killtcp control"
+	    return
+	fi
+	if [ $_killcount -eq 0 ] ; then
+	    return
+	fi
+
+	_count=0
+	while : ; do
+	    if [ -z "$(get_tcp_connections_for_ip $_ip)" ] ; then
+		echo "Killed $_killcount TCP connections to released IP $_ip"
+		return
+	    fi
+
+	    _count=$(($_count + 1))
+	    if [ $_count -gt 3 ] ; then
+		echo "Timed out killing tcp connections for IP $_ip"
+		return
+	    fi
+
+	    sleep 1
+	done
     }
-    _count=0
-    while netstat -tn |egrep "^tcp.*[[:space:]]+$_IP:.*ESTABLISHED" > /dev/null; do
-	sleep 1
-	_count=`expr $_count + 1`
-	[ $_count -gt 3 ] && {
-	    echo "Timed out killing tcp connections for IP $_IP"
-	    return;
-	}
-    done
-    echo "killed $_killcount TCP connections to released IP $_IP"
 }
 
 ##################################################################
 # kill off the local end for any TCP connections with the given IP
 ##################################################################
-kill_tcp_connections_local_only() {
-    _IP="$1"    
-    _failed=0
-
-    _killcount=0
-    connfile="$CTDB_VARDIR/state/connections.$_IP"
-    mkdir -p "${connfile%/*}" # dirname
-    netstat -tn |egrep "^tcp.*[[:space:]]+$_IP:.*ESTABLISHED" | awk '{print $4" "$5}' > $connfile
-    netstat -tn |egrep "^tcp.*[[:space:]]+::ffff:$_IP:.*ESTABLISHED" | awk '{print $4" "$5}' >> $connfile
-
-    while read dest src; do
-	srcip=`echo $src | sed -e "s/:[^:]*$//"`
-	srcport=`echo $src | sed -e "s/^.*://"`
-	destip=`echo $dest | sed -e "s/:[^:]*$//"`
-	destport=`echo $dest | sed -e "s/^.*://"`
-	echo "Killing TCP connection $srcip:$srcport $destip:$destport"
-	ctdb killtcp $srcip:$srcport $destip:$destport >/dev/null 2>&1 || _failed=1
-	_killcount=`expr $_killcount + 1`
-     done < $connfile
-    rm -f $connfile
-
-    [ $_failed = 0 ] || {
-	echo "Failed to send killtcp control"
-	return;
-    }
-    [ $_killcount -gt 0 ] || {
-	return;
-    }
-    _count=0
-    while netstat -tn |egrep "^tcp.*[[:space:]]+$_IP:.*ESTABLISHED" > /dev/null; do
-	sleep 1
-	_count=`expr $_count + 1`
-	[ $_count -gt 3 ] && {
-	    echo "Timed out killing tcp connections for IP $_IP"
-	    return;
-	}
-    done
-    echo "killed $_killcount TCP connections to released IP $_IP"
+kill_tcp_connections_local_only ()
+{
+    kill_tcp_connections "$1" "oneway"
 }
 
 ##################################################################
 # tickle any TCP connections with the given IP
 ##################################################################
-tickle_tcp_connections() {
-    _IP="$1"
-    _failed=0
-
-    _killcount=0
-    connfile="$CTDB_VARDIR/state/connections.$_IP"
-    mkdir -p "${connfile%/*}" # dirname
-    netstat -tn |egrep "^tcp.*[[:space:]]+$_IP:.*ESTABLISHED" | awk '{print $4" "$5}' > $connfile
-    netstat -tn |egrep "^tcp.*[[:space:]]+::ffff:$_IP:.*ESTABLISHED" | awk '{print $4" "$5}' >> $connfile
-
-    while read dest src; do
-	srcip=`echo $src | sed -e "s/:[^:]*$//"`
-	srcport=`echo $src | sed -e "s/^.*://"`
-	destip=`echo $dest | sed -e "s/:[^:]*$//"`
-	destport=`echo $dest | sed -e "s/^.*://"`
-	echo "Tickle TCP connection $srcip:$srcport $destip:$destport"
-	ctdb tickle $srcip:$srcport $destip:$destport >/dev/null 2>&1 || _failed=1
-	echo "Tickle TCP connection $destip:$destport $srcip:$srcport"
-	ctdb tickle $destip:$destport $srcip:$srcport >/dev/null 2>&1 || _failed=1
-     done < $connfile
-    rm -f $connfile
-
-    [ $_failed = 0 ] || {
-	echo "Failed to send tickle control"
-	return;
+tickle_tcp_connections ()
+{
+    _ip="$1"
+
+    get_tcp_connections_for_ip "$_ip" |
+    {
+	_failed=false
+
+	while read dest src; do
+	    echo "Tickle TCP connection $src $dest"
+	    ctdb tickle $src $dest >/dev/null 2>&1 || _failed=true
+	    echo "Tickle TCP connection $dest $src"
+	    ctdb tickle $dest $src >/dev/null 2>&1 || _failed=true
+	done
+
+	if $_failed ; then
+	    echo "Failed to send tickle control"
+	fi
     }
 }
 
+get_tcp_connections_for_ip ()
+{
+    _ip="$1"
+
+    netstat -tn | awk -v ip=$_ip \
+	'index($1, "tcp") == 1 && \
+	 (index($4, ip ":") == 1 || index($4, "::ffff:" ip ":") == 1) \
+	 && $6 == "ESTABLISHED" \
+	 {print $4" "$5}'
+}
+
 ########################################################
 # start/stop the Ganesha nfs service
 ########################################################
@@ -954,7 +938,7 @@ drop_all_public_ips ()
 # ctdb_check_counter_limit fails when count >= <limit>
 ########################################################
 _ctdb_counter_common () {
-    _service_name="${1:-${service_name}}"
+    _service_name="${1:-${service_name:-${script_name}}}"
     _counter_file="$ctdb_fail_dir/$_service_name"
     mkdir -p "${_counter_file%/*}" # dirname
 }
@@ -969,33 +953,6 @@ ctdb_counter_incr () {
     # unary counting!
     echo -n 1 >> "$_counter_file"
 }
-ctdb_check_counter_limit () {
-    _ctdb_counter_common
-
-    _limit="${1:-${service_fail_limit}}"
-    _quiet="$2"
-
-    # unary counting!
-    _size=$(stat -c "%s" "$_counter_file" 2>/dev/null || echo 0)
-    if [ $_size -ge $_limit ] ; then
-	echo "ERROR: more than $_limit consecutive failures for $service_name, marking cluster unhealthy"
-	exit 1
-    elif [ $_size -gt 0 -a -z "$_quiet" ] ; then
-	echo "WARNING: less than $_limit consecutive failures ($_size) for $service_name, not unhealthy yet"
-    fi
-}
-ctdb_check_counter_equal () {
-    _ctdb_counter_common
-
-    _limit=$1
-
-    # unary counting!
-    _size=$(stat -c "%s" "$_counter_file" 2>/dev/null || echo 0)
-    if [ $_size -eq $_limit ] ; then
-	return 1
-    fi
-    return 0
-}
 ctdb_check_counter () {
     _msg="${1:-error}"  # "error"  - anything else is silent on fail
     _op="${2:--ge}"  # an integer operator supported by test
@@ -1036,26 +993,25 @@ ctdb_managed_dir="$CTDB_VARDIR/managed_history"
 
 _ctdb_managed_common ()
 {
-    _service_name="${1:-${service_name}}"
-    _ctdb_managed_file="$ctdb_managed_dir/$_service_name"
+    _ctdb_managed_file="$ctdb_managed_dir/$service_name"
 }
 
 ctdb_service_managed ()
 {
-    _ctdb_managed_common "$@"
+    _ctdb_managed_common
     mkdir -p "$ctdb_managed_dir"
     touch "$_ctdb_managed_file"
 }
 
 ctdb_service_unmanaged ()
 {
-    _ctdb_managed_common "$@"
+    _ctdb_managed_common
     rm -f "$_ctdb_managed_file"
 }
 
 is_ctdb_previously_managed_service ()
 {
-    _ctdb_managed_common "$@"
+    _ctdb_managed_common
     [ -f "$_ctdb_managed_file" ]
 }
 
@@ -1101,35 +1057,35 @@ ctdb_setstatus ()
 
 _ctdb_service_reconfigure_common ()
 {
-    _d="$ctdb_status_dir/${1:-${service_name}}"
+    _d="$ctdb_status_dir/${service_name}"
     mkdir -p "$_d"
     _ctdb_service_reconfigure_flag="$_d/reconfigure"
 }
 
 ctdb_service_needs_reconfigure ()
 {


-- 
CTDB repository


More information about the samba-cvs mailing list