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.
This commit is contained in:
Bryan Boreham committed 2016-01-29 17:41:02 +00:00
1 parent 30fef10afa
commit a750ef8033
1 file changed
+5 -13
+5 -13
View File
@@ -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