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
|
# Parameters are container ID, CIDR address
|
||||||
configure_container_networking() {
|
configure_container_networking() {
|
||||||
container_netns_preamble $1
|
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;
|
# If veth name already exists then assume we set it up already;
|
||||||
# just add the IP address, if it's not already there
|
# just add the IP address, if it's not already there
|
||||||
if ip link show $LOCAL_IFNAME >/dev/null 2>&1 ; then
|
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 list dev $CONTAINER_IFNAME | grep -qF $2) 2>$IP_TMPFILE ; then
|
||||||
if ! ip netns exec $NSPID ip addr add $2 dev $CONTAINER_IFNAME ; then
|
if ip netns exec $NSPID ip addr add $2 dev $CONTAINER_IFNAME 2>$IP_TMPFILE ; then
|
||||||
echo "Failed to attach address $2 to container $1" >&2
|
EXITCODE=0 # succeeded in adding the address
|
||||||
container_netns_cleanup
|
|
||||||
return 1
|
|
||||||
fi
|
fi
|
||||||
|
else
|
||||||
|
EXITCODE=0 # address was there already
|
||||||
fi
|
fi
|
||||||
container_netns_cleanup
|
elif ip link add name $LOCAL_IFNAME mtu $MTU type veth peer name $GUEST_IFNAME mtu $MTU >$IP_TMPFILE 2>&1 ; then
|
||||||
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
|
|
||||||
if (ip link set $LOCAL_IFNAME master $BRIDGE &&
|
if (ip link set $LOCAL_IFNAME master $BRIDGE &&
|
||||||
ip link set $LOCAL_IFNAME up &&
|
ip link set $LOCAL_IFNAME up &&
|
||||||
ip link set $GUEST_IFNAME netns $NSPID) >$IP_TMPFILE 2>&1
|
ip link set $GUEST_IFNAME netns $NSPID) >$IP_TMPFILE 2>&1
|
||||||
@@ -185,23 +181,33 @@ detach() {
|
|||||||
container_netns_preamble $1
|
container_netns_preamble $1
|
||||||
|
|
||||||
EXITCODE=1
|
EXITCODE=1
|
||||||
if ip netns exec $NSPID ip addr list dev $CONTAINER_IFNAME | grep -qF $2 ; then
|
IP_TMPFILE=/tmp/weave_ip_output_$$
|
||||||
if ip netns exec $NSPID ip addr del $2 dev $CONTAINER_IFNAME ; then
|
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 no inet addresses remain then delete the veth
|
||||||
if [ -z "$(ip netns exec $NSPID ip -f inet addr list dev ethwe)" ] ; 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 ; then
|
if ip link del $LOCAL_IFNAME type veth 2>$IP_TMPFILE ; then
|
||||||
EXITCODE=0
|
EXITCODE=0
|
||||||
else
|
|
||||||
echo "Failed to delete virtual ethernet device $LOCAL_IFNAME from container $1" >&2
|
|
||||||
fi
|
fi
|
||||||
else
|
else
|
||||||
EXITCODE=0
|
EXITCODE=0
|
||||||
fi
|
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
|
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
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
rm -f $IP_TMPFILE
|
||||||
container_netns_cleanup
|
container_netns_cleanup
|
||||||
return $EXITCODE
|
return $EXITCODE
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in new issue
Block a user