8567: Add start_docker and kill_docker functions with wait loops.
[arvados.git] / docker / migrate-docker19 / migrate.sh
index 63d7274360941e9639d646b6d45daf0518a43d18..8e39be45678aa357632dd7e4dd0bb147bcdeebc3 100755 (executable)
@@ -2,8 +2,39 @@
 
 set -e
 
-/root/dnd.sh &
-sleep 2
+function start_docker {
+    /root/dnd.sh &
+    for i in $(seq 1 10) ; do
+        if docker version >/dev/null 2>/dev/null ; then
+            return
+        fi
+        sleep 1
+    done
+    false
+}
+
+function kill_docker {
+    if test -f /var/run/docker.pid ; then
+        kill $(cat /var/run/docker.pid)
+    fi
+    for i in $(seq 1 10) ; do
+        if ! docker version >/dev/null 2>/dev/null ; then
+            return
+        fi
+        sleep 1
+    done
+    false
+}
+
+function cleanup {
+    kill_docker
+    rm -rf /var/lib/docker/*
+    rm -rf /root/.cache/arvados/docker/*
+}
+
+trap cleanup EXIT
+
+start_docker
 
 image_tar_keepref=$1
 image_id=$2
@@ -17,22 +48,15 @@ docker tag $image_id $image_repo:$image_tag
 
 docker images -a
 
-kill $(cat /var/run/docker.pid)
-sleep 1
+kill_docker
 
 cd /root/pkgs
-dpkg -i libltdl7_2.4.2-1.11+b1_amd64.deb  docker-engine_1.13.1-0~debian-jessie_amd64.deb
+dpkg -i libltdl7_2.4.2-1.11+b1_amd64.deb docker-engine_1.13.1-0~debian-jessie_amd64.deb
 
-/root/dnd.sh &
-sleep 2
+start_docker
 
 docker images -a
 
-UUID=$(arv-keepdocker --project-uuid=$project_uuid $image_repo $image_tag)
-
-kill $(cat /var/run/docker.pid)
-sleep 1
-
-chmod ugo+rwx -R /var/lib/docker
+UUID=$(arv-keepdocker --force-image-format --project-uuid=$project_uuid $image_repo $image_tag)
 
 echo "Migrated uuid is $UUID"