Skip to contentSkip to conversation

postgresql: updates to get things working with systemd

PATCH New Mark Asselstine 1 participant 1 message Nov 22, 2017

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 postgresql: updates to get things working with systemd

Convert the sysvinit code to instead work with systemd. We are no longer able to make use of postinst scripts as we need to perform setup after the postgresql service is started, this will have 'knock-on' effects for other postinst, such as for keystone. Changing these postinst to "one time" services buys us greater control and easier readability than the postinst scripts, so overall this is a good change.

---
 .../classes/hosts.bbclass                          |   2 +-
 .../postgresql/postgresql/postgresql               | 117 ++++++---------------
 .../postgresql/postgresql/postgresql-init          |   9 +-
 .../postgresql/postgresql/postgresql-init.service  |  12 +++
 .../postgresql/postgresql_9.%.bbappend             |  65 +++++-------
 5 files changed, 78 insertions(+), 127 deletions(-)
 create mode 100644 meta-openstack/recipes-support/postgresql/postgresql/postgresql-init.service
meta-openstack-controller-deploy/classes/hosts.bbclass +1 -1
index d4062b4..07fa727 100644
@@ -5,4 +5,4 @@ CONTROLLER_IP ?= "192.168.7.2"
 CONTROLLER_HOST ?= "controller"
 MY_IP ?= "${CONTROLLER_IP}"
 MY_HOST ?= "${CONTROLLER_HOST}"
-DB_DATADIR ?= "/etc/postgresql"
+DB_DATADIR ?= "/etc/postgresql/data"
meta-openstack/recipes-support/postgresql/postgresql/postgresql +32 -85

125 lines not on this page · raw message

meta-openstack/recipes-support/postgresql/postgresql/postgresql-init +6 -3
index f5e7dfb..cc7b13e 100644
@@ -18,11 +18,14 @@ if [ -e $DATA_DIR/PG_VERSION ]; then
     exit 0
 fi
 
+# 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
-/etc/init.d/postgresql start
+systemctl restart postgresql
 
 count=0
 done=0
@@ -30,9 +33,9 @@ while [ $count -le 10 ] && [ $done -eq 0 ]; do
     sudo -u postgres psql -c "CREATE ROLE ${DB_USER} WITH SUPERUSER LOGIN PASSWORD '${DB_PASSWORD}'" 2> /dev/null
     if [ $? -ne 0 ]; then
         echo "[INFO] postgres: failed to create account for ${DB_USER}, trying again"
-        /etc/init.d/postgresql stop
+        systemctl stop postresql
 	sleep 3
-        /etc/init.d/postgresql start
+        systemctl start postgresql
 	sleep 3
     else
         echo "[INFO] postgres: created account for ${DB_USER}, continuing .. "
meta-openstack/recipes-support/postgresql/postgresql/postgresql-init.service new file +12 -0
new file mode 100644
index 0000000..94206d2
@@ -0,0 +1,12 @@
+[Unit]
+Description=Postgresql setup for OpenStack
+After=postgresql.service
+
+[Service]
+Type=oneshot
+ExecStart=%SYSCONFIGDIR%/postgresql/postgresql-init
+ExecStartPost=/bin/systemctl --no-reload disable postgresql-init.service
+RemainAfterExit=No
+
+[Install]
+WantedBy=multi-user.target
meta-openstack/recipes-support/postgresql/postgresql_9.%.bbappend +27 -38

84 lines not on this page · raw message

Signature · 1 line
2.7.4