File tree Expand file tree Collapse file tree 1 file changed +14
-5
lines changed
Expand file tree Collapse file tree 1 file changed +14
-5
lines changed Original file line number Diff line number Diff line change @@ -11,21 +11,30 @@ function init_pg() {
1111 DB_USER=${DB_USER:- postgres}
1212
1313 export DB_NAME DB_PASSWORD DB_ENGINE DB_HOST DB_PORT DB_USER
14-
1514 if [[ ${DB_HOST} != " 127.0.0.1" ]]; then
1615 echo " External database skip start, ${DB_HOST} "
1716 return
1817 fi
1918
19+ PG_CLUSTER_INFO=$( pg_lsclusters --no-header | awk ' NR==1' )
20+ if [[ -z " $PG_CLUSTER_INFO " ]]; then
21+ echo " No PostgreSQL cluster found"
22+ return 1
23+ fi
24+
25+ PG_VERSION=$( echo " $PG_CLUSTER_INFO " | awk ' {print $1}' )
26+ PG_CLUSTER=$( echo " $PG_CLUSTER_INFO " | awk ' {print $2}' )
27+ PG_DATA_DIR=$( echo " $PG_CLUSTER_INFO " | awk ' {print $6}' )
28+
2029 echo " >> Start database postgre"
21- chown -R postgres:postgres /var/lib/postgresql/13/main
22- pg_ctlcluster 13 main start
30+ chown -R postgres:postgres ${PG_DATA_DIR}
31+ pg_ctlcluster ${PG_VERSION} ${PG_CLUSTER} start
2332 sleep 3
2433
25- if [[ ! -f /var/lib/postgresql/13/main /inited.txt ]]; then
34+ if [[ ! -f ${PG_DATA_DIR} /inited.txt ]]; then
2635 sudo -u postgres psql -c " ALTER USER postgres PASSWORD '$DB_PASSWORD ';"
2736 sudo -u postgres psql -c " CREATE DATABASE $DB_NAME ;"
28- touch /var/lib/postgresql/13/main /inited.txt
37+ touch ${PG_DATA_DIR} /inited.txt
2938 fi
3039}
3140
You can’t perform that action at this time.
0 commit comments