summaryrefslogtreecommitdiff
path: root/tcwg-start-container.sh
diff options
context:
space:
mode:
authorMaxim Kuvyrkov <maxim.kuvyrkov@linaro.org>2020-05-13 14:55:13 +0000
committerMaxim Kuvyrkov <maxim.kuvyrkov@linaro.org>2020-05-13 14:55:13 +0000
commitf362d7f03b41898cb77901b01afab5efbf59016c (patch)
tree5e6985eb02e0d04c24eea089c6bb1b9d008f6f46 /tcwg-start-container.sh
parenta3a66e895bbe44c9d6e40bb130b6b76530ab48bd (diff)
tcwg-start-container.sh: Support restarting container from itself
... which is useful for "host" and "jenkins" containers. Change-Id: Id1b4ff181d31de791b3f8934ebcd3889a0d16610
Diffstat (limited to 'tcwg-start-container.sh')
-rwxr-xr-xtcwg-start-container.sh15
1 files changed, 13 insertions, 2 deletions
diff --git a/tcwg-start-container.sh b/tcwg-start-container.sh
index ea4d95d3..c9929eec 100755
--- a/tcwg-start-container.sh
+++ b/tcwg-start-container.sh
@@ -19,8 +19,9 @@ if $verbose; then set -x; fi
# shellcheck disable=SC2154
docker pull "$image"
+rm_cnt=""
# shellcheck disable=SC2154
-if docker stats --no-stream $container >/dev/null 2>&1; then
+if docker stats --no-stream "$container" >/dev/null 2>&1; then
case "$keep_existing" in
true) exit 0 ;;
keep_if_same_image)
@@ -31,7 +32,9 @@ if docker stats --no-stream $container >/dev/null 2>&1; then
fi
;;
esac
- docker rm -vf $container
+ # Rename the current container to free-up the name for "docker run" below.
+ rm_cnt="$container.bak"
+ docker rename "$container" "$rm_cnt"
fi
start_sh=$(mktemp)
@@ -39,3 +42,11 @@ docker run --rm $image start.sh > "$start_sh"
bash "$start_sh" "$@"
rm "$start_sh"
+
+if [ x"$rm_cnt" != x"" ]; then
+ # With the new container started delete the old one.
+ # 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 rm -vf "$rm_cnt"
+fi