Script: return a container name when it's not running.

Do status checks in the same way.
This commit is contained in:
jansorg 2018-11-15 11:05:00 +01:00 committed by Grégoire Henry
parent d4864216b4
commit 1d204cd83c
No known key found for this signature in database
GPG Key ID: 50D984F20BD445D2

View File

@ -190,7 +190,8 @@ assert_container() {
} }
container_name() { 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 #################################################################### ## Node ####################################################################
@ -215,8 +216,8 @@ clear_node_volume() {
check_node() { check_node() {
res=$(docker inspect \ res=$(docker inspect \
--format="{{ .State.Running }}" \ --format="{{ .State.Running }}" \
--type=container "$(container_name "$docker_node_container")" 2>/dev/null) --type=container "$(container_name "$docker_node_container")" 2>/dev/null || echo false)
[ -n "$res" ] [ "$res" = "true" ]
} }
assert_node() { assert_node() {
@ -287,8 +288,8 @@ check_baker() {
docker_baker_containers="$(sed "s/^\(.*\)$/${docker_compose_name}_baker-\1_1/g" "$active_protocol_versions")" docker_baker_containers="$(sed "s/^\(.*\)$/${docker_compose_name}_baker-\1_1/g" "$active_protocol_versions")"
res=$(docker inspect \ res=$(docker inspect \
--format="{{ .State.Running }}" \ --format="{{ .State.Running }}" \
--type=container "$(container_name "$docker_baker_containers")" 2>/dev/null) --type=container "$(container_name "$docker_baker_containers")" 2>/dev/null || echo false)
[ -n "$res" ] [ "$res" = "true" ]
} }
assert_baker() { assert_baker() {
@ -352,8 +353,8 @@ check_endorser() {
docker_endorser_containers="$(sed "s/^\(.*\)$/${docker_compose_name}_endorser-\1_1/g" "$active_protocol_versions")" docker_endorser_containers="$(sed "s/^\(.*\)$/${docker_compose_name}_endorser-\1_1/g" "$active_protocol_versions")"
res=$(docker inspect \ res=$(docker inspect \
--format="{{ .State.Running }}" \ --format="{{ .State.Running }}" \
--type=container "$(container_name "$docker_endorser_containers")" 2>/dev/null) --type=container "$(container_name "$docker_endorser_containers")" 2>/dev/null || echo false)
[ -n "$res" ] [ "$res" = "true" ]
} }
assert_endorser() { assert_endorser() {
@ -417,8 +418,8 @@ check_accuser() {
docker_accuser_containers="$(sed "s/^\(.*\)$/${docker_compose_name}_accuser-\1_1/g" "$active_protocol_versions")" docker_accuser_containers="$(sed "s/^\(.*\)$/${docker_compose_name}_accuser-\1_1/g" "$active_protocol_versions")"
res=$(docker inspect \ res=$(docker inspect \
--format="{{ .State.Running }}" \ --format="{{ .State.Running }}" \
--type=container "$(container_name "$docker_accuser_containers")" 2>/dev/null) --type=container "$(container_name "$docker_accuser_containers")" 2>/dev/null || echo false)
[ -n "$res" ] [ "$res" = "true" ]
} }
assert_accuser() { assert_accuser() {