From dc2f28f7c988364b5d45f3048be4db3e5ff113b3 Mon Sep 17 00:00:00 2001 From: Ronnie Sahlberg Date: Tue, 24 Mar 2009 14:05:31 +1100 Subject: [PATCH] create a varient of kill_tcp_connections that only kills off the local side of a connection --- config/events.d/91.lvs | 2 +- config/functions | 42 ++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 43 insertions(+), 1 deletion(-) diff --git a/config/events.d/91.lvs b/config/events.d/91.lvs index 4860030a..2411d1e0 100755 --- a/config/events.d/91.lvs +++ b/config/events.d/91.lvs @@ -52,7 +52,7 @@ case $cmd in # kill off any tcp connections ipvsadm -D -t $CTDB_LVS_PUBLIC_IP:0 ipvsadm -D -u $CTDB_LVS_PUBLIC_IP:0 - kill_tcp_connections $CTDB_LVS_PUBLIC_IP + kill_tcp_connections_local_only $CTDB_LVS_PUBLIC_IP PNN=`ctdb pnn | sed -e "s/.*PNN://"` LVSMASTER=`ctdb lvsmaster | sed -e "s/.*Node //" -e "s/ .*//"` diff --git a/config/functions b/config/functions index 1073055f..2f0b01fe 100644 --- a/config/functions +++ b/config/functions @@ -311,6 +311,48 @@ kill_tcp_connections() { 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_BASE/state/connections.$_IP" + 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 + /bin/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" +} + ######################################################## # start/stop the nfs service on different platforms ######################################################## -- 2.34.1