From 5a12ffced73dc36dde5f38d6abc3645a82ed2b83 Mon Sep 17 00:00:00 2001 From: Guillaume Pellerin Date: Wed, 28 Mar 2018 16:31:48 +0200 Subject: [PATCH] Fix wait for restoring DB --- dev/local/restore_db.sh | 7 ++----- dev/restore_db.sh | 4 +++- misc/wait.sh | 13 ++++++++----- 3 files changed, 13 insertions(+), 11 deletions(-) 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 -- 2.39.5