Skip to contentSkip to conversation

postgresql: follow move to recipes-dbs done in meta-openembedded

PATCH In review Mark Asselstine 2 participants 4 messages Mar 29, 2018 – Apr 4, 2018

lore
Share & tools
lore
#0 lore raw

PATCH 1/3 postgresql: follow move to recipes-dbs done in meta-openembedded

Commit 742404cc8ab0 [postgres: move to recipes-dbs] in meta-openembedded moved the postgresql recipe to recipes-dbs. We usually try to match the bbappend's path with that of the bb so complete a matching move here.

---
 .../{recipes-support => recipes-dbs}/postgresql/postgresql/postgresql     | 0
 .../postgresql/postgresql/postgresql-init                                 | 0
 .../postgresql/postgresql/postgresql-init.service                         | 0
 .../{recipes-support => recipes-dbs}/postgresql/postgresql_9.%.bbappend   | 0
 4 files changed, 0 insertions(+), 0 deletions(-)
 rename meta-openstack/{recipes-support => recipes-dbs}/postgresql/postgresql/postgresql (100%)
 rename meta-openstack/{recipes-support => recipes-dbs}/postgresql/postgresql/postgresql-init (100%)
 rename meta-openstack/{recipes-support => recipes-dbs}/postgresql/postgresql/postgresql-init.service (100%)
 rename meta-openstack/{recipes-support => recipes-dbs}/postgresql/postgresql_9.%.bbappend (100%)
meta-openstack/recipes-dbs/postgresql/postgresql/postgresql renamed from meta-openstack/recipes-support/postgresql/postgresql/postgresql +0 -0
similarity index 100%
rename from meta-openstack/recipes-support/postgresql/postgresql/postgresql
rename to meta-openstack/recipes-dbs/postgresql/postgresql/postgresql
meta-openstack/recipes-dbs/postgresql/postgresql/postgresql-init renamed from meta-openstack/recipes-support/postgresql/postgresql/postgresql-init +0 -0
similarity index 100%
rename from meta-openstack/recipes-support/postgresql/postgresql/postgresql-init
rename to meta-openstack/recipes-dbs/postgresql/postgresql/postgresql-init
meta-openstack/recipes-dbs/postgresql/postgresql/postgresql-init.service renamed from meta-openstack/recipes-support/postgresql/postgresql/postgresql-init.service +0 -0
similarity index 100%
rename from meta-openstack/recipes-support/postgresql/postgresql/postgresql-init.service
rename to meta-openstack/recipes-dbs/postgresql/postgresql/postgresql-init.service
meta-openstack/recipes-dbs/postgresql/postgresql_9.%.bbappend renamed from meta-openstack/recipes-support/postgresql/postgresql_9.%.bbappend +0 -0
similarity index 100%
rename from meta-openstack/recipes-support/postgresql/postgresql_9.%.bbappend
rename to meta-openstack/recipes-dbs/postgresql/postgresql_9.%.bbappend
Signature · 1 line
2.7.4
#1 lore raw

PATCH 2/3 postgresql: update all instances of PGDATA

While investigating a postgresql startup issue I found we were only updating one instance of PGDATA where several exist. We do not use these other instances but they are files installed in the system and should reflect our customized setting for PGDATA.

---
 meta-openstack/recipes-dbs/postgresql/postgresql_9.%.bbappend | 11 ++++++++++-
 1 file changed, 10 insertions(+), 1 deletion(-)
meta-openstack/recipes-dbs/postgresql/postgresql_9.%.bbappend +10 -1
index 5b87960..1b8a952 100644
@@ -19,7 +19,6 @@ do_install_append() {
     install -m 0755 ${WORKDIR}/postgresql-init ${D_DEST_DIR}/postgresql-init
 
     sed -e "s:%DB_DATADIR%:${DB_DATADIR}:g" -i ${D_DEST_DIR}/postgresql-init
-    sed -e "s:\(PGDATA=\).*$:\1${DB_DATADIR}:g" -i ${D}${systemd_unitdir}/system/postgresql.service
 
     sed -e "s:%DB_USER%:${DB_USER}:g" -i ${D_DEST_DIR}/postgresql-init
     sed -e "s:%DB_PASSWORD%:${DB_PASSWORD}:g" -i ${D_DEST_DIR}/postgresql-init
@@ -34,6 +33,16 @@ do_install_append() {
     PG_INIT_SERVICE_FILE=${D}${systemd_unitdir}/system/postgresql-init.service
     install -m 644 ${WORKDIR}/postgresql-init.service ${PG_INIT_SERVICE_FILE}
     sed -e "s:%SYSCONFIGDIR%:${sysconfdir}:g" -i ${PG_INIT_SERVICE_FILE}
+
+    # Update PGDATA throughout
+    files="${D}${localstatedir}/lib/${BPN}/.bash_profile"
+    files="$files ${D}${systemd_unitdir}/system/postgresql.service"
+    files="$files ${D}${bindir}/${BPN}-setup"
+    files="$files ${D}${sysconfdir}/init.d/${BPN}-server"
+    for f in $files
+    do
+        sed -e "s:\(PGDATA=\).*$:\1${DB_DATADIR}:g" -i $f
+    done
 }
 
 PACKAGES += " ${PN}-setup"
Signature · 1 line
2.7.4
#2 lore raw

PATCH 3/3 postgresql: don't attempt to start the DB before we setup the DB

In reply to Mark Asselstine

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.

---
 .../postgresql/postgresql/postgresql-init          | 36 +++++++++++++---------
 .../recipes-dbs/postgresql/postgresql_9.%.bbappend |  5 +++
 2 files changed, 26 insertions(+), 15 deletions(-)
meta-openstack/recipes-dbs/postgresql/postgresql/postgresql-init +21 -15
index cc7b13e..e1f9484 100644
@@ -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
meta-openstack/recipes-dbs/postgresql/postgresql_9.%.bbappend +5 -0
index 1b8a952..5bf25e1 100644
@@ -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"
Signature · 1 line
2.7.4
#3 lore raw
In reply to Mark Asselstine

The series has been merged.

Bruce

Quoted 41 lines · Mark Asselstine

Commit 742404cc8ab0 [postgres: move to recipes-dbs] in meta-openembedded moved the postgresql recipe to recipes-dbs. We usually try to match the bbappend's path with that of the bb so complete a matching move here.

---
 .../{recipes-support => recipes-dbs}/postgresql/postgresql/postgresql     | 0
 .../postgresql/postgresql/postgresql-init                                 | 0
 .../postgresql/postgresql/postgresql-init.service                         | 0
 .../{recipes-support => recipes-dbs}/postgresql/postgresql_9.%.bbappend   | 0
 4 files changed, 0 insertions(+), 0 deletions(-)
 rename meta-openstack/{recipes-support => recipes-dbs}/postgresql/postgresql/postgresql (100%)
 rename meta-openstack/{recipes-support => recipes-dbs}/postgresql/postgresql/postgresql-init (100%)
 rename meta-openstack/{recipes-support => recipes-dbs}/postgresql/postgresql/postgresql-init.service (100%)
 rename meta-openstack/{recipes-support => recipes-dbs}/postgresql/postgresql_9.%.bbappend (100%)
meta-openstack/recipes-dbs/postgresql/postgresql/postgresql renamed from meta-openstack/recipes-support/postgresql/postgresql/postgresql +0 -0
similarity index 100%
rename from meta-openstack/recipes-support/postgresql/postgresql/postgresql
rename to meta-openstack/recipes-dbs/postgresql/postgresql/postgresql
meta-openstack/recipes-dbs/postgresql/postgresql/postgresql-init renamed from meta-openstack/recipes-support/postgresql/postgresql/postgresql-init +0 -0
similarity index 100%
rename from meta-openstack/recipes-support/postgresql/postgresql/postgresql-init
rename to meta-openstack/recipes-dbs/postgresql/postgresql/postgresql-init
meta-openstack/recipes-dbs/postgresql/postgresql/postgresql-init.service renamed from meta-openstack/recipes-support/postgresql/postgresql/postgresql-init.service +0 -0
similarity index 100%
rename from meta-openstack/recipes-support/postgresql/postgresql/postgresql-init.service
rename to meta-openstack/recipes-dbs/postgresql/postgresql/postgresql-init.service
meta-openstack/recipes-dbs/postgresql/postgresql_9.%.bbappend renamed from meta-openstack/recipes-support/postgresql/postgresql_9.%.bbappend +0 -1
similarity index 100%
rename from meta-openstack/recipes-support/postgresql/postgresql_9.%.bbappend
rename to meta-openstack/recipes-dbs/postgresql/postgresql_9.%.bbappend
--

2.7.4

--
_______________________________________________
meta-virtualization mailing list
[email protected]
https://lists.yoctoproject.org/listinfo/meta-virtualization

Signature · 2 lines
"Thou shalt not follow the NULL pointer, for chaos and madness await
thee at its end"