diff --git a/msa/tb/docker-cassandra/start-db.sh b/msa/tb/docker-cassandra/start-db.sh index 92423de9a8..8f8e4a7c35 100644 --- a/msa/tb/docker-cassandra/start-db.sh +++ b/msa/tb/docker-cassandra/start-db.sh @@ -32,6 +32,13 @@ if [ ! -f ${firstlaunch} ]; then do sleep 1 done +else + RETRIES="${PG_ISREADY_RETRIES:-300}" + until pg_isready -U ${pkg.user} -d thingsboard --quiet || [ $RETRIES -eq 0 ] + do + echo "Connecting to Postgres, $((RETRIES--)) attempts left..." + sleep 1 + done fi cassandra_data_dir=${CASSANDRA_DATA} diff --git a/msa/tb/docker-postgres/start-db.sh b/msa/tb/docker-postgres/start-db.sh index def5165f7a..0962968222 100644 --- a/msa/tb/docker-postgres/start-db.sh +++ b/msa/tb/docker-postgres/start-db.sh @@ -22,22 +22,21 @@ 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 thingsboard -d postgres -c "CREATE DATABASE thingsboard" + while ! psql -U ${pkg.user} -d postgres -c "CREATE DATABASE thingsboard" do sleep 1 done else - until pg_isready --dbname thingsboard --quiet + RETRIES="${PG_ISREADY_RETRIES:-300}" + until pg_isready -U ${pkg.user} -d thingsboard --quiet || [ $RETRIES -eq 0 ] do + echo "Connecting to Postgres, $((RETRIES--)) attempts left..." sleep 1 - echo "Waiting for db" done fi