From: Guillaume Pellerin Date: Wed, 28 Mar 2018 14:31:48 +0000 (+0200) Subject: Fix wait for restoring DB X-Git-Url: https://git.parisson.com/?a=commitdiff_plain;h=5a12ffced73dc36dde5f38d6abc3645a82ed2b83;p=docker-django-scripts.git Fix wait for restoring DB --- diff --git a/dev/local/restore_db.sh b/dev/local/restore_db.sh index 27915f0..b48c057 100755 --- a/dev/local/restore_db.sh +++ b/dev/local/restore_db.sh @@ -1,11 +1,8 @@ #!/bin/bash -# import dump functions of the database (postgres or mysql) -# export POSTGRES="$(dpkg --get-selections | grep postgres 2>&1)" -# export MYSQL="$(dpkg --get-selections | grep mysql 2>&1)" +set -e -# wait for db -# /srv/bin/misc/wait.sh +echo "Restoring..." # import database functions of type if [ ! -z "$MYSQL_ROOT_PASSWORD" ]; then diff --git a/dev/restore_db.sh b/dev/restore_db.sh index 53b9bc4..5916ad5 100755 --- a/dev/restore_db.sh +++ b/dev/restore_db.sh @@ -1,3 +1,5 @@ #!/bin/sh -docker-compose run db /srv/bin/dev/local/restore_db.sh +docker-compose up -d db +docker-compose run db bash -c "/srv/bin/misc/wait.sh; /srv/bin/dev/local/restore_db.sh; /srv/bin/dev/local/restore_db.sh" +docker-compose stop db diff --git a/misc/wait.sh b/misc/wait.sh index 202c4d1..26a309f 100755 --- a/misc/wait.sh +++ b/misc/wait.sh @@ -1,13 +1,16 @@ -#!/bin/sh +#!/bin/bash set -e -host=$(env | grep _TCP_ADDR | cut -d = -f 2) -port=$(env | grep _TCP_PORT | cut -d = -f 2) +apt update +apt install -y netcat -echo -n "waiting for TCP connection to $host:$port..." +HOST=db +PORT=5432 -while ! nc -w 1 $host $port 2>/dev/null +echo -n "waiting for TCP connection to $HOST:$PORT..." + +while ! nc -w 1 $HOST $PORT 2>/dev/null do echo -n . sleep 1