Postgres startup script improved. will wait for postgres is ready about 300+ seconds. Postgres may do some recovery stuff on startup.

This commit is contained in:
Sergey Matvienko 2022-06-14 19:16:38 +03:00
parent 605c32123f
commit 4e0e1d3cae
2 changed files with 11 additions and 5 deletions

View File

@ -32,6 +32,13 @@ if [ ! -f ${firstlaunch} ]; then
do do
sleep 1 sleep 1
done 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 fi
cassandra_data_dir=${CASSANDRA_DATA} cassandra_data_dir=${CASSANDRA_DATA}

View File

@ -22,22 +22,21 @@ PG_CTL=$(find /usr/lib/postgresql/ -name pg_ctl)
if [ ! -d ${PGDATA} ]; then if [ ! -d ${PGDATA} ]; then
mkdir -p ${PGDATA} mkdir -p ${PGDATA}
${PG_CTL} initdb ${PG_CTL} initdb
else
${PG_CTL} start
fi fi
exec setsid nohup postgres >> ${PGLOG}/postgres.log 2>&1 & exec setsid nohup postgres >> ${PGLOG}/postgres.log 2>&1 &
if [ ! -f ${firstlaunch} ]; then if [ ! -f ${firstlaunch} ]; then
sleep 2 sleep 2
while ! psql -U thingsboard -d postgres -c "CREATE DATABASE thingsboard" while ! psql -U ${pkg.user} -d postgres -c "CREATE DATABASE thingsboard"
do do
sleep 1 sleep 1
done done
else 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 do
echo "Connecting to Postgres, $((RETRIES--)) attempts left..."
sleep 1 sleep 1
echo "Waiting for db"
done done
fi fi