From 7d5153f52ee4033c8a7ffab0a678950122b982eb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20Kwakernaak?= <58462885+andre-aktivconsultancy@users.noreply.github.com> Date: Thu, 23 Dec 2021 10:55:20 +0100 Subject: [PATCH] ensure postgres database is always started The Postgres database would only get started on first launch. When starting a second time e.g. after a `docker-compose down` and `docker-compose up`, the database was not started resulting in a failure when ThingsBoard is starting. --- msa/tb/docker-postgres/start-db.sh | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/msa/tb/docker-postgres/start-db.sh b/msa/tb/docker-postgres/start-db.sh index 1688bba79e..94cb004012 100644 --- a/msa/tb/docker-postgres/start-db.sh +++ b/msa/tb/docker-postgres/start-db.sh @@ -22,14 +22,22 @@ PG_CTL=$(find /usr/lib/postgresql/ -name pg_ctl) if [ ! -d ${PGDATA} ]; then mkdir -p ${PGDATA} ${PG_CTL} initdb +else + ${PG_CTL} start fi exec setsid nohup postgres >> ${PGLOG}/postgres.log 2>&1 & if [ ! -f ${firstlaunch} ]; then sleep 2 - while ! psql -U ${pkg.user} -d postgres -c "CREATE DATABASE thingsboard" + while ! psql -U thingsboard -d postgres -c "CREATE DATABASE thingsboard" do sleep 1 done -fi \ No newline at end of file +else + until pg_isready --dbname thingsboard --quiet + do + sleep 1 + echo "Waiting for db" + done +fi