If and only if network setup because the container died, say so.

This involves capturing stderr output from all the 'ip' commands so we
can hide that output if we see the process died, or show it to the user
if the process didn't die, in which case we don't know why we failed.
This commit is contained in:
Bryan Boreham committed 2014-09-18 11:24:08 +01:00
1 parent bfd5007339
commit a75a0d8709
1 file changed
+19 -8
+19 -8
View File
@@ -120,15 +120,16 @@ configure_container_networking() {
EXITCODE=1
LOCAL_IFNAME="v${CONTAINER_IFNAME}pl${NSPID}"
GUEST_IFNAME="v${CONTAINER_IFNAME}pg${NSPID}"
if ip link add name $LOCAL_IFNAME mtu $MTU type veth peer name $GUEST_IFNAME mtu $MTU ; then
if ip link set $LOCAL_IFNAME master $BRIDGE && \
ip link set $LOCAL_IFNAME up && \
ip link set $GUEST_IFNAME netns $NSPID
IP_TMPFILE=/tmp/weave_ip_output_$$
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 &&
ip link set $LOCAL_IFNAME up &&
ip link set $GUEST_IFNAME netns $NSPID) > $IP_TMPFILE 2>&1
then
ip netns exec $NSPID ip link set $GUEST_IFNAME name $CONTAINER_IFNAME && \
ip netns exec $NSPID ip addr add $2 dev $CONTAINER_IFNAME && \
ip netns exec $NSPID ip link set $CONTAINER_IFNAME up && \
(check_command_and_run ethtool ip netns exec $NSPID ethtool -K $3 tx off >/dev/null) && \
(ip netns exec $NSPID ip link set $GUEST_IFNAME name $CONTAINER_IFNAME &&
ip netns exec $NSPID ip addr add $2 dev $CONTAINER_IFNAME &&
ip netns exec $NSPID ip link set $CONTAINER_IFNAME up &&
check_command_and_run ethtool ip netns exec $NSPID ethtool -K $3 tx off) > $IP_TMPFILE 2>&1 &&
EXITCODE=0
else
# failed before we assigned the veth to the container's namespace - delete it
@@ -136,6 +137,16 @@ configure_container_networking() {
fi
fi
if [ "$EXITCODE" -ne 0 ] ; then
if ! ps -p $DOCKERPID > /dev/null 2>&1 ; then
echo "Container died during network set-up. ID $1" >&2
else
echo "Failure during network set-up:" >&2
cat $IP_TMPFILE
fi
fi
rm -f $IP_TMPFILE
rm -f /var/run/netns/$NSPID
return $EXITCODE