diff options
author | Mark Asselstine <mark.asselstine@windriver.com> | 2018-03-29 15:29:11 -0400 |
---|---|---|
committer | Bruce Ashfield <bruce.ashfield@windriver.com> | 2018-04-03 23:23:43 -0400 |
commit | b8c333d8ac7944478b448768465b988d64b34582 (patch) | |
tree | 9d1c21918c885f47210f7269fd01aa39c182be89 /meta-openstack/recipes-dbs/postgresql | |
parent | 8145053096e29032fa96c77df8b60db2a4164762 (diff) | |
download | meta-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')
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] | ||
2 | Description=PostgreSQL database server | ||
3 | After=network.target | ||
4 | |||
5 | [Service] | ||
6 | Type=forking | ||
7 | |||
8 | User=postgres | ||
9 | Group=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 | ||
17 | OOMScoreAdjust=-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) | ||
20 | Environment=PG_OOM_ADJUST_FILE=/proc/self/oom_score_adj | ||
21 | Environment=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. | ||
25 | Environment=PGSTARTTIMEOUT=270 | ||
26 | |||
27 | Environment=PGDATA=/usr/local/pgsql/data | ||
28 | |||
29 | |||
30 | ExecStart=/usr/local/pgsql/bin/pg_ctl start -D ${PGDATA} -s -w -t ${PGSTARTTIMEOUT} | ||
31 | ExecStop=/usr/local/pgsql/bin/pg_ctl stop -D ${PGDATA} -s -m fast | ||
32 | ExecReload=/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. | ||
37 | TimeoutSec=300 | ||
38 | |||
39 | [Install] | ||
40 | WantedBy=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 | |||
4 | PN=postgresql | ||
5 | CONTROLLER_IP=%CONTROLLER_IP% | ||
6 | COMPUTE_IP=%COMPUTE_IP% | ||
7 | DB_USER=%DB_USER% | ||
8 | DB_PASSWORD=%DB_PASSWORD% | ||
9 | DATA_DIR=%DB_DATADIR% | ||
10 | |||
11 | if [ ! -e $DATA_DIR ]; then | ||
12 | mkdir -p $DATA_DIR | ||
13 | chown postgres $DATA_DIR | ||
14 | fi | ||
15 | |||
16 | if [ -e $DATA_DIR/PG_VERSION ]; then | ||
17 | # the database has already been initialized, return | ||
18 | exit 0 | ||
19 | fi | ||
20 | |||
21 | # Create the DB | ||
22 | sudo -u postgres initdb -D $DATA_DIR | ||
23 | |||
24 | # Allow readers/writers by IP | ||
25 | echo "listen_addresses = '*'" >> $DATA_DIR/postgresql.conf | ||
26 | echo "host all all ${CONTROLLER_IP}/32 trust" >> $DATA_DIR/pg_hba.conf | ||
27 | echo "host all all ${COMPUTE_IP}/32 trust" >> $DATA_DIR/pg_hba.conf | ||
28 | systemctl restart postgresql | ||
29 | |||
30 | count=0 | ||
31 | done=0 | ||
32 | while [ $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` | ||
45 | done | ||
46 | |||
47 | if [ $done -eq 0 ]; then | ||
48 | echo "[ERROR] postgres: unable to create admin account" | ||
49 | exit 1 | ||
50 | fi | ||
51 | |||
52 | ln -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] | ||
2 | Description=Postgresql setup for OpenStack | ||
3 | After=postgresql.service | ||
4 | |||
5 | [Service] | ||
6 | Type=oneshot | ||
7 | ExecStart=%SYSCONFIGDIR%/postgresql/postgresql-init | ||
8 | ExecStartPost=/bin/systemctl --no-reload disable postgresql-init.service | ||
9 | RemainAfterExit=No | ||
10 | |||
11 | [Install] | ||
12 | WantedBy=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 @@ | |||
1 | FILESEXTRAPATHS_prepend := "${THISDIR}/${PN}:" | ||
2 | |||
3 | SRC_URI += " \ | ||
4 | file://postgresql-init \ | ||
5 | file://postgresql-init.service \ | ||
6 | " | ||
7 | |||
8 | inherit identity hosts | ||
9 | |||
10 | SYSTEMD_AUTO_ENABLE_${PN} = "enable" | ||
11 | |||
12 | # default | ||
13 | DB_DATADIR ?= "/var/lib/postgres/data" | ||
14 | |||
15 | do_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 | |||
39 | PACKAGES += " ${PN}-setup" | ||
40 | |||
41 | SYSTEMD_PACKAGES += "${PN}-setup" | ||
42 | SYSTEMD_SERVICE_${PN}-setup = "postgresql-init.service" | ||
43 | |||
44 | FILES_${PN}-setup = " \ | ||
45 | ${systemd_unitdir}/system \ | ||
46 | " | ||