summaryrefslogtreecommitdiffstats
path: root/meta-openstack/recipes-dbs/postgresql
diff options
context:
space:
mode:
authorMark Asselstine <mark.asselstine@windriver.com>2018-03-29 15:29:11 -0400
committerBruce Ashfield <bruce.ashfield@windriver.com>2018-04-03 23:23:43 -0400
commitb8c333d8ac7944478b448768465b988d64b34582 (patch)
tree9d1c21918c885f47210f7269fd01aa39c182be89 /meta-openstack/recipes-dbs/postgresql
parent8145053096e29032fa96c77df8b60db2a4164762 (diff)
downloadmeta-cloud-services-b8c333d8ac7944478b448768465b988d64b34582.tar.gz
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. Signed-off-by: Mark Asselstine <mark.asselstine@windriver.com> Signed-off-by: Bruce Ashfield <bruce.ashfield@windriver.com>
Diffstat (limited to 'meta-openstack/recipes-dbs/postgresql')
-rw-r--r--meta-openstack/recipes-dbs/postgresql/postgresql/postgresql40
-rw-r--r--meta-openstack/recipes-dbs/postgresql/postgresql/postgresql-init52
-rw-r--r--meta-openstack/recipes-dbs/postgresql/postgresql/postgresql-init.service12
-rw-r--r--meta-openstack/recipes-dbs/postgresql/postgresql_9.%.bbappend46
4 files changed, 150 insertions, 0 deletions
diff --git a/meta-openstack/recipes-dbs/postgresql/postgresql/postgresql b/meta-openstack/recipes-dbs/postgresql/postgresql/postgresql
new file mode 100644
index 0000000..2bdd582
--- /dev/null
+++ b/meta-openstack/recipes-dbs/postgresql/postgresql/postgresql
@@ -0,0 +1,40 @@
1[Unit]
2Description=PostgreSQL database server
3After=network.target
4
5[Service]
6Type=forking
7
8User=postgres
9Group=postgres
10
11# Where to send early-startup messages from the server (before the logging
12# options of postgresql.conf take effect)
13# This is normally controlled by the global default set by systemd
14# StandardOutput=syslog
15
16# Disable OOM kill on the postmaster
17OOMScoreAdjust=-1000
18# ... but allow it still to be effective for child processes
19# (note that these settings are ignored by Postgres releases before 9.5)
20Environment=PG_OOM_ADJUST_FILE=/proc/self/oom_score_adj
21Environment=PG_OOM_ADJUST_VALUE=0
22
23# Maximum number of seconds pg_ctl will wait for postgres to start. Note that
24# PGSTARTTIMEOUT should be less than TimeoutSec value.
25Environment=PGSTARTTIMEOUT=270
26
27Environment=PGDATA=/usr/local/pgsql/data
28
29
30ExecStart=/usr/local/pgsql/bin/pg_ctl start -D ${PGDATA} -s -w -t ${PGSTARTTIMEOUT}
31ExecStop=/usr/local/pgsql/bin/pg_ctl stop -D ${PGDATA} -s -m fast
32ExecReload=/usr/local/pgsql/bin/pg_ctl reload -D ${PGDATA} -s
33
34# Give a reasonable amount of time for the server to start up/shut down.
35# Ideally, the timeout for starting PostgreSQL server should be handled more
36# nicely by pg_ctl in ExecStart, so keep its timeout smaller than this value.
37TimeoutSec=300
38
39[Install]
40WantedBy=multi-user.target
diff --git a/meta-openstack/recipes-dbs/postgresql/postgresql/postgresql-init b/meta-openstack/recipes-dbs/postgresql/postgresql/postgresql-init
new file mode 100644
index 0000000..cc7b13e
--- /dev/null
+++ b/meta-openstack/recipes-dbs/postgresql/postgresql/postgresql-init
@@ -0,0 +1,52 @@
1#!/bin/sh
2# set -x
3
4PN=postgresql
5CONTROLLER_IP=%CONTROLLER_IP%
6COMPUTE_IP=%COMPUTE_IP%
7DB_USER=%DB_USER%
8DB_PASSWORD=%DB_PASSWORD%
9DATA_DIR=%DB_DATADIR%
10
11if [ ! -e $DATA_DIR ]; then
12 mkdir -p $DATA_DIR
13 chown postgres $DATA_DIR
14fi
15
16if [ -e $DATA_DIR/PG_VERSION ]; then
17 # the database has already been initialized, return
18 exit 0
19fi
20
21# Create the DB
22sudo -u postgres initdb -D $DATA_DIR
23
24# Allow readers/writers by IP
25echo "listen_addresses = '*'" >> $DATA_DIR/postgresql.conf
26echo "host all all ${CONTROLLER_IP}/32 trust" >> $DATA_DIR/pg_hba.conf
27echo "host all all ${COMPUTE_IP}/32 trust" >> $DATA_DIR/pg_hba.conf
28systemctl restart postgresql
29
30count=0
31done=0
32while [ $count -le 10 ] && [ $done -eq 0 ]; do
33 sudo -u postgres psql -c "CREATE ROLE ${DB_USER} WITH SUPERUSER LOGIN PASSWORD '${DB_PASSWORD}'" 2> /dev/null
34 if [ $? -ne 0 ]; then
35 echo "[INFO] postgres: failed to create account for ${DB_USER}, trying again"
36 systemctl stop postresql
37 sleep 3
38 systemctl start postgresql
39 sleep 3
40 else
41 echo "[INFO] postgres: created account for ${DB_USER}, continuing .. "
42 done=1
43 fi
44 count=`expr $count + 1`
45done
46
47if [ $done -eq 0 ]; then
48 echo "[ERROR] postgres: unable to create admin account"
49 exit 1
50fi
51
52ln -s /usr/share/zoneinfo /usr/share/postgresql/timezone || true
diff --git a/meta-openstack/recipes-dbs/postgresql/postgresql/postgresql-init.service b/meta-openstack/recipes-dbs/postgresql/postgresql/postgresql-init.service
new file mode 100644
index 0000000..94206d2
--- /dev/null
+++ b/meta-openstack/recipes-dbs/postgresql/postgresql/postgresql-init.service
@@ -0,0 +1,12 @@
1[Unit]
2Description=Postgresql setup for OpenStack
3After=postgresql.service
4
5[Service]
6Type=oneshot
7ExecStart=%SYSCONFIGDIR%/postgresql/postgresql-init
8ExecStartPost=/bin/systemctl --no-reload disable postgresql-init.service
9RemainAfterExit=No
10
11[Install]
12WantedBy=multi-user.target
diff --git a/meta-openstack/recipes-dbs/postgresql/postgresql_9.%.bbappend b/meta-openstack/recipes-dbs/postgresql/postgresql_9.%.bbappend
new file mode 100644
index 0000000..5b87960
--- /dev/null
+++ b/meta-openstack/recipes-dbs/postgresql/postgresql_9.%.bbappend
@@ -0,0 +1,46 @@
1FILESEXTRAPATHS_prepend := "${THISDIR}/${PN}:"
2
3SRC_URI += " \
4 file://postgresql-init \
5 file://postgresql-init.service \
6 "
7
8inherit identity hosts
9
10SYSTEMD_AUTO_ENABLE_${PN} = "enable"
11
12# default
13DB_DATADIR ?= "/var/lib/postgres/data"
14
15do_install_append() {
16 D_DEST_DIR=${D}${sysconfdir}/postgresql
17
18 install -d ${D_DEST_DIR}
19 install -m 0755 ${WORKDIR}/postgresql-init ${D_DEST_DIR}/postgresql-init
20
21 sed -e "s:%DB_DATADIR%:${DB_DATADIR}:g" -i ${D_DEST_DIR}/postgresql-init
22 sed -e "s:\(PGDATA=\).*$:\1${DB_DATADIR}:g" -i ${D}${systemd_unitdir}/system/postgresql.service
23
24 sed -e "s:%DB_USER%:${DB_USER}:g" -i ${D_DEST_DIR}/postgresql-init
25 sed -e "s:%DB_PASSWORD%:${DB_PASSWORD}:g" -i ${D_DEST_DIR}/postgresql-init
26
27 sed -e "s:%CONTROLLER_IP%:${CONTROLLER_IP}:g" -i ${D_DEST_DIR}/postgresql-init
28 sed -e "s:%CONTROLLER_HOST%:${CONTROLLER_HOST}:g" -i ${D_DEST_DIR}/postgresql-init
29
30 sed -e "s:%COMPUTE_IP%:${COMPUTE_IP}:g" -i ${D_DEST_DIR}/postgresql-init
31 sed -e "s:%COMPUTE_HOST%:${COMPUTE_HOST}:g" -i ${D_DEST_DIR}/postgresql-init
32
33 install -d ${D}${systemd_unitdir}/system/
34 PG_INIT_SERVICE_FILE=${D}${systemd_unitdir}/system/postgresql-init.service
35 install -m 644 ${WORKDIR}/postgresql-init.service ${PG_INIT_SERVICE_FILE}
36 sed -e "s:%SYSCONFIGDIR%:${sysconfdir}:g" -i ${PG_INIT_SERVICE_FILE}
37}
38
39PACKAGES += " ${PN}-setup"
40
41SYSTEMD_PACKAGES += "${PN}-setup"
42SYSTEMD_SERVICE_${PN}-setup = "postgresql-init.service"
43
44FILES_${PN}-setup = " \
45 ${systemd_unitdir}/system \
46"