[meta-virtualization] [m-c-s][PATCH 3/3] postgresql: don't attempt to start the DB before we setup the DB
Mark Asselstine
mark.asselstine at windriver.com
Thu Mar 29 12:29:13 PDT 2018
When we boot the first time the postgresql service will [FAIL] and
the following error is reported:
pg_ctl[288]: pg_ctl: directory "/etc/postgresql/data" does not exist
This is a result of the service being started before a call to
postgresql's initdb is made on the PGDATA directory, usually made by
the package's default 'postgresql-setup' or our 'postgresql-init'
scripts.
We split our 'postgresql-init' script into two, the first part which
does the 'initdb' can be executed as part of the postgresql.service
'ExecStartPre' allowing the postgresql.service to not fail. The
remainder of 'postgresql-init' script is executed as before, via the
postgresql-init.service on first boot.
This change also fixes some of the first boot startup races that was
preventing some of the openstack '*-init' services which do DB
configuration for openstack components from executing correctly.
Signed-off-by: Mark Asselstine <mark.asselstine at windriver.com>
---
.../postgresql/postgresql/postgresql-init | 36 +++++++++++++---------
.../recipes-dbs/postgresql/postgresql_9.%.bbappend | 5 +++
2 files changed, 26 insertions(+), 15 deletions(-)
diff --git a/meta-openstack/recipes-dbs/postgresql/postgresql/postgresql-init b/meta-openstack/recipes-dbs/postgresql/postgresql/postgresql-init
index cc7b13e..e1f9484 100644
--- a/meta-openstack/recipes-dbs/postgresql/postgresql/postgresql-init
+++ b/meta-openstack/recipes-dbs/postgresql/postgresql/postgresql-init
@@ -8,24 +8,30 @@ DB_USER=%DB_USER%
DB_PASSWORD=%DB_PASSWORD%
DATA_DIR=%DB_DATADIR%
-if [ ! -e $DATA_DIR ]; then
- mkdir -p $DATA_DIR
- chown postgres $DATA_DIR
-fi
+initdb(){
+ if [ ! -e $DATA_DIR ]; then
+ mkdir -p $DATA_DIR
+ chown postgres $DATA_DIR
+ fi
-if [ -e $DATA_DIR/PG_VERSION ]; then
- # the database has already been initialized, return
- exit 0
-fi
+ if [ -e $DATA_DIR/PG_VERSION ]; then
+ # the database has already been initialized, return
+ exit 0
+ fi
+
+ # Create the DB
+ sudo -u postgres initdb -D $DATA_DIR
-# Create the DB
-sudo -u postgres initdb -D $DATA_DIR
+ # Allow readers/writers by IP
+ echo "listen_addresses = '*'" >> $DATA_DIR/postgresql.conf
+ echo "host all all ${CONTROLLER_IP}/32 trust" >> $DATA_DIR/pg_hba.conf
+ echo "host all all ${COMPUTE_IP}/32 trust" >> $DATA_DIR/pg_hba.conf
+ }
-# Allow readers/writers by IP
-echo "listen_addresses = '*'" >> $DATA_DIR/postgresql.conf
-echo "host all all ${CONTROLLER_IP}/32 trust" >> $DATA_DIR/pg_hba.conf
-echo "host all all ${COMPUTE_IP}/32 trust" >> $DATA_DIR/pg_hba.conf
-systemctl restart postgresql
+if [ "$1" == "initdb" ]; then
+ initdb
+ exit 0
+fi
count=0
done=0
diff --git a/meta-openstack/recipes-dbs/postgresql/postgresql_9.%.bbappend b/meta-openstack/recipes-dbs/postgresql/postgresql_9.%.bbappend
index 1b8a952..5bf25e1 100644
--- a/meta-openstack/recipes-dbs/postgresql/postgresql_9.%.bbappend
+++ b/meta-openstack/recipes-dbs/postgresql/postgresql_9.%.bbappend
@@ -43,6 +43,11 @@ do_install_append() {
do
sed -e "s:\(PGDATA=\).*$:\1${DB_DATADIR}:g" -i $f
done
+
+ # Ensure DB is initialize before we attempt to start the service
+ FILE=${D}${systemd_unitdir}/system/postgresql.service
+ sed -e '/ExecStart=.*/i ExecStartPre=-${sysconfdir}/postgresql/postgresql-init initdb' -i $FILE
+ sed -e '/ExecStartPre=.*/i PermissionsStartOnly=true' -i $FILE
}
PACKAGES += " ${PN}-setup"
--
2.7.4
More information about the meta-virtualization
mailing list