From a750ef8033337647eb31cff8e61563b018be98d4 Mon Sep 17 00:00:00 2001 From: Bryan Boreham Date: Mon, 11 Jan 2016 16:29:00 +0000 Subject: [PATCH] Don't check if container is running when we only want its ID. This avoids trying to decide if "restarting" is as good as "running". In wait_for_status we now explitly check_running, and in dns_add/remove we add an extra check_running test. --- weave | 18 +++++------------- 1 file changed, 5 insertions(+), 13 deletions(-) diff --git a/weave b/weave index b2da6ed8..fe071c42 100755 --- a/weave +++ b/weave @@ -951,23 +951,14 @@ stop() { } # Given a container name or short ID in $1, ensure the specified -# container is running and then print its full ID to stdout. If -# it's not running or doesn't exist, print an error to stderr and +# container exists and then print its full ID to stdout. If +# it doesn't exist, print an error to stderr and # return with an indicative non-zero exit code. container_id() { - if ! status=$(docker inspect --format='{{.State.Running}} {{.Id}}' $1 2>/dev/null) ; then + if ! docker inspect --format='{{.Id}}' $1 2>/dev/null ; then echo "Error: No such container: $1" >&2 return 1 fi - case "$status" in - true*) - echo "${status#true }" - ;; - *) - echo "$1 container is not running." >&2 - return 2 - ;; - esac } container_ip() { @@ -1033,7 +1024,7 @@ wait_for_status() { shift while true ; do "$@" GET /status >/dev/null 2>&1 && return 0 - if ! container_id $container >/dev/null 2>&1 ; then + if ! check_running $container >/dev/null 2>&1 ; then echo $(death_msg $container) >&2 return 1 fi @@ -1286,6 +1277,7 @@ collect_dns_add_remove_args() { [ $# -eq 0 -a \( -n "$C" -o \( $IP_COUNT -gt 0 -a -n "$FQDN" \) \) ] || usage check_running $CONTAINER_NAME if [ -n "$C" ] ; then + check_running $C CONTAINER=$(container_id $C) [ $IP_COUNT -gt 0 ] || IP_ARGS=$(with_container_addresses echo_ips $CONTAINER) fi