From cac74122f204bfb13e9e277901b9a385c75f4135 Mon Sep 17 00:00:00 2001 From: Jose Fuentes Date: Mon, 17 Dec 2018 13:09:32 +0100 Subject: Wait for DB on boot --- stacksmith/user-scripts/run.sh | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) (limited to 'stacksmith/user-scripts/run.sh') diff --git a/stacksmith/user-scripts/run.sh b/stacksmith/user-scripts/run.sh index e7cc6df6..2aea7ea0 100755 --- a/stacksmith/user-scripts/run.sh +++ b/stacksmith/user-scripts/run.sh @@ -1,10 +1,20 @@ #!/bin/bash -set -euxo pipefail +set -euo pipefail readonly CONF=/build/env.config source ${CONF} +# wait for DB +check_db() { + mongo $MONGO_URL --eval "db.runCommand( { connectionStatus: 1} )" --quiet | python -c 'import json,sys;obj=json.load(sys.stdin);code = 0 if obj["ok"]==1 else 1; sys.exit(code);' +} +until check_db; do + period=5 + echo "Cannot connect to db, waiting ${period} seconds before trying again..." + sleep ${period} +done + cd /build echo "starting the wekan service..." node main.js -- cgit v1.2.3-1-g7c22