1
0
mirror of https://github.com/samba-team/samba.git synced 2024-12-22 13:34:15 +03:00

ctdb-scripts: Use ctdb_killtcp helper to kill connections

ctdb_killtcp will take up to 5 seconds to kill connections, so don't
wait in a loop.  Just check if there are remaining connections on
completion and log a message either way.

Also add a test stub.

Signed-off-by: Martin Schwenke <martin@meltin.net>
Reviewed-by: Amitay Isaacs <amitay@gmail.com>
This commit is contained in:
Martin Schwenke 2016-03-11 15:30:47 +11:00 committed by Amitay Isaacs
parent b417d79930
commit 83502a79dc
3 changed files with 19 additions and 21 deletions

View File

@ -464,29 +464,21 @@ kill_tcp_connections ()
return
fi
echo "$_connections" | ctdb killtcp || {
echo "Failed to send killtcp control"
return
echo "$_connections" | \
"${CTDB_HELPER_BINDIR}/ctdb_killtcp" "$_iface" || {
echo "Failed to kill TCP connections"
return
}
_count=0
while : ; do
_remaining=$(get_tcp_connections_for_ip $_ip | wc -l)
_remaining=$(get_tcp_connections_for_ip $_ip | wc -l)
if [ $_remaining -eq 0 ] ; then
if [ $_remaining -eq 0 ] ; then
echo "Killed $_killcount TCP connections to released IP $_ip"
return
fi
fi
_count=$(($_count + 1))
if [ $_count -gt 3 ] ; then
echo "Timed out killing tcp connections for IP $_ip ($_remaining remaining)"
return
fi
echo "Waiting for $_remaining connections to be killed for IP $_ip"
sleep 1
done
_t="${_remaining}/${_killcount}"
echo "Failed to kill TCP connections for IP $_ip (${_t} remaining)"
}
}

View File

@ -31,10 +31,7 @@ while read dev ip bits ; do
ok <<EOF
Killing TCP connection 10.254.254.1:43210 ${ip}:445
$out
Waiting for 1 connections to be killed for IP ${ip}
Waiting for 1 connections to be killed for IP ${ip}
Waiting for 1 connections to be killed for IP ${ip}
Timed out killing tcp connections for IP $ip (1 remaining)
Failed to kill TCP connections for IP 10.0.0.3 (1/11 remaining)
EOF
simple_test $dev $ip $bits

View File

@ -0,0 +1,9 @@
#!/bin/sh
# Only supports reading from stdin
iface="$1" # ignored
while read src dst ; do
sed -i -e "/^${dst} ${src}\$/d" "$FAKE_NETSTAT_TCP_ESTABLISHED_FILE"
done