ditch check_command_and_run wrapper

Since we end up swallowing the warning when wanting to redirect stderr
of the command execution.

Fixes #286.
This commit is contained in:
Matthias Radestock committed 2014-12-21 15:07:21 +00:00
1 parent 66e55ee421
commit 41cb8a1215
1 file changed
+18 -21
+18 -21
View File
@@ -24,12 +24,6 @@ usage() {
exit 1 exit 1
} }
# utility function to check whether a command can be executed by the shell
# see http://stackoverflow.com/questions/592620/how-to-check-if-a-program-exists-from-a-bash-script
command_exists () {
command -v $1 >/dev/null 2>&1
}
[ `id -u` = 0 ] || { [ `id -u` = 0 ] || {
echo "weave must be run as 'root'" >&2 echo "weave must be run as 'root'" >&2
exit 1 exit 1
@@ -53,18 +47,17 @@ COMMAND=$1
shift 1 shift 1
check_command_and_run_anything() { # utility function to check whether a command can be executed by the shell
if command_exists $1 # see http://stackoverflow.com/questions/592620/how-to-check-if-a-program-exists-from-a-bash-script
then command_exists () {
shift 1 command -v $1 >/dev/null 2>&1
"$@"
else
echo "Cannot find $1; please install it. Continuing without it." >&2
fi
} }
check_command_and_run() { command_exists_or_warn () {
check_command_and_run_anything $1 "$@" if ! command_exists $1 ; then
echo "Cannot find $1; please install it. Continuing without it." >&2
return 1
fi
} }
is_cidr() { is_cidr() {
@@ -124,7 +117,7 @@ create_bridge() {
ip link set dev v${CONTAINER_IFNAME}du master $BRIDGE ip link set dev v${CONTAINER_IFNAME}du master $BRIDGE
ip link del dev v${CONTAINER_IFNAME}du ip link del dev v${CONTAINER_IFNAME}du
# disable offloading # disable offloading
check_command_and_run ethtool -K $BRIDGE tx off >/dev/null if command_exists_or_warn ethtool; then ethtool -K $BRIDGE tx off >/dev/null; fi
# Work around the situation where there are no rules allowing traffic # Work around the situation where there are no rules allowing traffic
# across our bridge. E.g. ufw # across our bridge. E.g. ufw
add_iptables_rule filter FORWARD -i $BRIDGE -o $BRIDGE -j ACCEPT add_iptables_rule filter FORWARD -i $BRIDGE -o $BRIDGE -j ACCEPT
@@ -205,7 +198,7 @@ connect_container_to_bridge() {
return 1 return 1
fi fi
if check_command_and_run ethtool -K $GUEST_IFNAME tx off >/dev/null && if { if command_exists_or_warn ethtool; then ethtool -K $GUEST_IFNAME tx off >/dev/null; fi } &&
ip link set $LOCAL_IFNAME master $BRIDGE && 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 $NETNS ; then ip link set $GUEST_IFNAME netns $NETNS ; then
@@ -224,7 +217,7 @@ launch() {
return 1 return 1
fi fi
connect_container_to_bridge && connect_container_to_bridge &&
check_command_and_run_anything ethtool ip netns exec $NETNS ethtool -K eth0 tx off >/dev/null && { if command_exists_or_warn ethtool ; then ip netns exec $NETNS ethtool -K eth0 tx off >/dev/null; fi } &&
ip netns exec $NETNS ip link set $CONTAINER_IFNAME up ip netns exec $NETNS ip link set $CONTAINER_IFNAME up
} }
@@ -552,7 +545,9 @@ case "$COMMAND" in
echo "Weave is not running." >&2 echo "Weave is not running." >&2
fi fi
docker rm -f $CONTAINER_NAME >/dev/null 2>&1 || true docker rm -f $CONTAINER_NAME >/dev/null 2>&1 || true
check_command_and_run conntrack -D -p udp --dport $PORT >/dev/null 2>&1 || true if command_exists_or_warn conntrack; then
conntrack -D -p udp --dport $PORT >/dev/null 2>&1 || true
fi
;; ;;
stop-dns) stop-dns)
[ $# -eq 0 ] || usage [ $# -eq 0 ] || usage
@@ -567,7 +562,9 @@ case "$COMMAND" in
docker kill $DNS_CONTAINER_NAME >/dev/null 2>&1 || true docker kill $DNS_CONTAINER_NAME >/dev/null 2>&1 || true
docker rm -f $CONTAINER_NAME >/dev/null 2>&1 || true docker rm -f $CONTAINER_NAME >/dev/null 2>&1 || true
docker rm -f $DNS_CONTAINER_NAME >/dev/null 2>&1 || true docker rm -f $DNS_CONTAINER_NAME >/dev/null 2>&1 || true
check_command_and_run conntrack -D -p udp --dport $PORT >/dev/null 2>&1 || true if command_exists_or_warn conntrack; then
conntrack -D -p udp --dport $PORT >/dev/null 2>&1 || true
fi
destroy_bridge destroy_bridge
for LOCAL_IFNAME in $(ip link show | grep v${CONTAINER_IFNAME}pl | cut -d ' ' -f 2 | tr -d ':') ; do for LOCAL_IFNAME in $(ip link show | grep v${CONTAINER_IFNAME}pl | cut -d ' ' -f 2 | tr -d ':') ; do
ip link del $LOCAL_IFNAME ip link del $LOCAL_IFNAME