From 1898c47f2a9f7e44215a2f3a6c78b0855d96b576 Mon Sep 17 00:00:00 2001 From: George Vlahavas Date: Wed, 17 Mar 2021 19:37:01 +0200 Subject: [PATCH] Loop until all all containers are up --- deploy.sh | 43 ++++++++++++++++++++++++++++++++++++++----- 1 file changed, 38 insertions(+), 5 deletions(-) diff --git a/deploy.sh b/deploy.sh index 409f297..0e6a149 100755 --- a/deploy.sh +++ b/deploy.sh @@ -17,14 +17,47 @@ docker run --rm -v $(pwd):/app \ cd .. sh ./create_volumes.sh +# Keep the timestamp of when starting up containers +TIME_START=`date +%s` + # Run containers docker-compose -f docker-compose-jfrog.yml up --detach -# Wait until everything is up, 2 mins should be enough. -sleep 120 + +# loop until all containers are up +while 1; do + # if any container other than composer has exited, bail out + res=`docker ps -a | \ + grep "/curex-local/kea_" | \ + grep -v "kea_composer" | \ + grep "Exited" | \ + wc -l` + if [ $res -gt 0 ]; then + echo "ERROR: Some containers have exited." + docker ps -a | grep "/curex-local/kea_" + exit 1 + fi + # count containers that are up + res=`docker ps -a | \ + grep "/curex-local/kea_" | \ + grep -v "kea_composer" | \ + grep "Up" | \ + wc -l` + if [ $res -eq 11 ]; then + break + fi + # only wait for 10 mins until everything is up. It should be more than + # enough. + TIME_NOW=`date +%s` + if [ $((TIME_NOW - TIME_START)) -ge 600 ]; then + echo "ERROR: Timeout exceeded." + exit 2 + fi + sleep 1 +done + +# Wait a bit more +sleep 10 # create and populate the database docker-compose -f docker-compose-jfrog.yml exec api php artisan migrate:fresh --seed --force -#Check that everything is running succesfully -docker ps -a | grep "^CONTAINER\|/curex-local/kea_" - -- 2.2.2