From 1d204cd83c54d22bdfd68d852f3737cfdea0783a Mon Sep 17 00:00:00 2001 From: jansorg Date: Thu, 15 Nov 2018 11:05:00 +0100 Subject: [PATCH] Script: return a container name when it's not running. Do status checks in the same way. --- scripts/alphanet.sh | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/scripts/alphanet.sh b/scripts/alphanet.sh index 95a7a1503..bf2e4c8ae 100755 --- a/scripts/alphanet.sh +++ b/scripts/alphanet.sh @@ -190,7 +190,8 @@ assert_container() { } container_name() { - docker ps --filter "name=$1" --format "{{.Names}}" + local name="$(docker ps --filter "name=$1" --format "{{.Names}}")" + if [ -n "$name" ]; then echo "$name"; else echo "$1"; fi } ## Node #################################################################### @@ -215,8 +216,8 @@ clear_node_volume() { check_node() { res=$(docker inspect \ --format="{{ .State.Running }}" \ - --type=container "$(container_name "$docker_node_container")" 2>/dev/null) - [ -n "$res" ] + --type=container "$(container_name "$docker_node_container")" 2>/dev/null || echo false) + [ "$res" = "true" ] } assert_node() { @@ -287,8 +288,8 @@ check_baker() { docker_baker_containers="$(sed "s/^\(.*\)$/${docker_compose_name}_baker-\1_1/g" "$active_protocol_versions")" res=$(docker inspect \ --format="{{ .State.Running }}" \ - --type=container "$(container_name "$docker_baker_containers")" 2>/dev/null) - [ -n "$res" ] + --type=container "$(container_name "$docker_baker_containers")" 2>/dev/null || echo false) + [ "$res" = "true" ] } assert_baker() { @@ -352,8 +353,8 @@ check_endorser() { docker_endorser_containers="$(sed "s/^\(.*\)$/${docker_compose_name}_endorser-\1_1/g" "$active_protocol_versions")" res=$(docker inspect \ --format="{{ .State.Running }}" \ - --type=container "$(container_name "$docker_endorser_containers")" 2>/dev/null) - [ -n "$res" ] + --type=container "$(container_name "$docker_endorser_containers")" 2>/dev/null || echo false) + [ "$res" = "true" ] } assert_endorser() { @@ -417,8 +418,8 @@ check_accuser() { docker_accuser_containers="$(sed "s/^\(.*\)$/${docker_compose_name}_accuser-\1_1/g" "$active_protocol_versions")" res=$(docker inspect \ --format="{{ .State.Running }}" \ - --type=container "$(container_name "$docker_accuser_containers")" 2>/dev/null) - [ -n "$res" ] + --type=container "$(container_name "$docker_accuser_containers")" 2>/dev/null || echo false) + [ "$res" = "true" ] } assert_accuser() {