Capture error output from ip command and check if error was caused by container dying
This commit is contained in:
1 parent
8e50e0759d
commit
9e3cbba275
1 file changed
+26
-20
+26
-20
@@ -131,25 +131,21 @@ container_netns_cleanup() {
|
||||
# Parameters are container ID, CIDR address
|
||||
configure_container_networking() {
|
||||
container_netns_preamble $1
|
||||
EXITCODE=1
|
||||
IP_TMPFILE=/tmp/weave_ip_output_$$
|
||||
rm -f $IP_TMPFILE
|
||||
|
||||
# If veth name already exists then assume we set it up already;
|
||||
# just add the IP address, if it's not already there
|
||||
if ip link show $LOCAL_IFNAME >/dev/null 2>&1 ; then
|
||||
if ! ip netns exec $NSPID ip addr list dev $CONTAINER_IFNAME | grep -qF $2 ; then
|
||||
if ! ip netns exec $NSPID ip addr add $2 dev $CONTAINER_IFNAME ; then
|
||||
echo "Failed to attach address $2 to container $1" >&2
|
||||
container_netns_cleanup
|
||||
return 1
|
||||
if ! (ip netns exec $NSPID ip addr list dev $CONTAINER_IFNAME | grep -qF $2) 2>$IP_TMPFILE ; then
|
||||
if ip netns exec $NSPID ip addr add $2 dev $CONTAINER_IFNAME 2>$IP_TMPFILE ; then
|
||||
EXITCODE=0 # succeeded in adding the address
|
||||
fi
|
||||
else
|
||||
EXITCODE=0 # address was there already
|
||||
fi
|
||||
container_netns_cleanup
|
||||
return 0
|
||||
fi
|
||||
|
||||
EXITCODE=1
|
||||
IP_TMPFILE=/tmp/weave_ip_output_$$
|
||||
rm -f $IP_TMPFILE
|
||||
if ip link add name $LOCAL_IFNAME mtu $MTU type veth peer name $GUEST_IFNAME mtu $MTU >$IP_TMPFILE 2>&1 ; then
|
||||
elif ip link add name $LOCAL_IFNAME mtu $MTU type veth peer name $GUEST_IFNAME mtu $MTU >$IP_TMPFILE 2>&1 ; then
|
||||
if (ip link set $LOCAL_IFNAME master $BRIDGE &&
|
||||
ip link set $LOCAL_IFNAME up &&
|
||||
ip link set $GUEST_IFNAME netns $NSPID) >$IP_TMPFILE 2>&1
|
||||
@@ -185,23 +181,33 @@ detach() {
|
||||
container_netns_preamble $1
|
||||
|
||||
EXITCODE=1
|
||||
if ip netns exec $NSPID ip addr list dev $CONTAINER_IFNAME | grep -qF $2 ; then
|
||||
if ip netns exec $NSPID ip addr del $2 dev $CONTAINER_IFNAME ; then
|
||||
IP_TMPFILE=/tmp/weave_ip_output_$$
|
||||
rm -f $IP_TMPFILE
|
||||
if (ip netns exec $NSPID ip addr list dev $CONTAINER_IFNAME | grep -qF $2) 2>$IP_TMPFILE ; then
|
||||
if ip netns exec $NSPID ip addr del $2 dev $CONTAINER_IFNAME 2>$IP_TMPFILE ; then
|
||||
# if no inet addresses remain then delete the veth
|
||||
if [ -z "$(ip netns exec $NSPID ip -f inet addr list dev ethwe)" ] ; then
|
||||
if ip link del $LOCAL_IFNAME type veth ; then
|
||||
if [ -z "$(ip netns exec $NSPID ip -f inet addr list dev ethwe 2>$IP_TMPFILE)" ] ; then
|
||||
if ip link del $LOCAL_IFNAME type veth 2>$IP_TMPFILE ; then
|
||||
EXITCODE=0
|
||||
else
|
||||
echo "Failed to delete virtual ethernet device $LOCAL_IFNAME from container $1" >&2
|
||||
fi
|
||||
else
|
||||
EXITCODE=0
|
||||
fi
|
||||
fi
|
||||
else
|
||||
EXITCODE=0
|
||||
fi
|
||||
|
||||
if [ "$EXITCODE" -ne 0 ] ; then
|
||||
if ! ps -p $DOCKERPID >/dev/null 2>&1 ; then
|
||||
echo "Container $1 died" >&2
|
||||
else
|
||||
echo "Failed to detach address $2 from container $1" >&2
|
||||
echo "Failure while detaching address $2 from container $1" >&2
|
||||
cat $IP_TMPFILE >&2
|
||||
fi
|
||||
fi
|
||||
|
||||
rm -f $IP_TMPFILE
|
||||
container_netns_cleanup
|
||||
return $EXITCODE
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user