diff options
author | Maxim Kuvyrkov <maxim.kuvyrkov@linaro.org> | 2021-10-22 08:50:16 +0000 |
---|---|---|
committer | Maxim Kuvyrkov <maxim.kuvyrkov@linaro.org> | 2021-10-22 08:50:16 +0000 |
commit | 0f81713dcb46bf0aec56b76b0eb154017fe109e1 (patch) | |
tree | 82c72bbfb9b71ae50e70e4cb23f8067cb89d4de0 | |
parent | 34eccce6e8a13debb97fd7aff6d6744c60baa35c (diff) |
tcwg-start-container.sh: Fix typo and improve container removal logic
Change-Id: Ice78502d4f41659ea4ec86a6238da3c12b5ab1c0
-rwxr-xr-x | tcwg-start-container.sh | 13 |
1 files changed, 9 insertions, 4 deletions
diff --git a/tcwg-start-container.sh b/tcwg-start-container.sh index 761bb26d..e93a0b5c 100755 --- a/tcwg-start-container.sh +++ b/tcwg-start-container.sh @@ -42,8 +42,9 @@ if docker stats --no-stream "$container" >/dev/null 2>&1; then # Failure to rename a container is usually caused by container # restarting loop. This restarting container can't be the current # one, so just delete it. - docker stop "$container" - docker rm -vf "$container" + if ! docker rm -v "$container"; then + docker rm -vf "$container" + fi rm_cnt="" fi fi @@ -71,6 +72,10 @@ if [ x"$rm_cnt" != x"" ]; then # Note that if both old and new containers need an exclusive resource # (e.g., tcp port or connection to jenkins), then the new container might # need to restart a couple of times to wait for removal of the old one. - docker stop "$container" - docker rm -vf "$rm_cnt" + # + # We first try to gracefully shutdown the container + if ! docker rm -v "$rm_cnt"; then + # ... and force SIGKILL only when necessary. + docker rm -fv "$rm_cnt" + fi fi |