summaryrefslogtreecommitdiffstats
path: root/meta-openstack
diff options
context:
space:
mode:
Diffstat (limited to 'meta-openstack')
-rw-r--r--meta-openstack/recipes-support/postgresql/postgresql/postgresql117
-rw-r--r--meta-openstack/recipes-support/postgresql/postgresql/postgresql-init9
-rw-r--r--meta-openstack/recipes-support/postgresql/postgresql/postgresql-init.service12
-rw-r--r--meta-openstack/recipes-support/postgresql/postgresql_9.%.bbappend65
4 files changed, 77 insertions, 126 deletions
diff --git a/meta-openstack/recipes-support/postgresql/postgresql/postgresql b/meta-openstack/recipes-support/postgresql/postgresql/postgresql
index cfff759..2bdd582 100644
--- a/meta-openstack/recipes-support/postgresql/postgresql/postgresql
+++ b/meta-openstack/recipes-support/postgresql/postgresql/postgresql
@@ -1,93 +1,40 @@
1#!/bin/sh 1[Unit]
2Description=PostgreSQL database server
3After=network.target
2 4
3### BEGIN INIT INFO 5[Service]
4# Provides: postgresql 6Type=forking
5# Required-Start: $local_fs $remote_fs $network $time
6# Required-Stop: $local_fs $remote_fs $network $time
7# Should-Start: $syslog
8# Should-Stop: $syslog
9# Default-Start: 2 3 4 5
10# Default-Stop: 0 1 6
11# Short-Description: PostgreSQL RDBMS server
12### END INIT INFO
13 7
14DAEMON=/usr/bin/postmaster 8User=postgres
15DESC="PostgreSQL RDBMS server" 9Group=postgres
16DEFAULT_DATA_DIR=%DB_DATADIR%
17 10
18datadir=`grep ^data_directory $DEFAULT_DATA_DIR/postgresql.conf |sed -e "s#^.*= '##; s#'.*##"` 11# Where to send early-startup messages from the server (before the logging
19if [ "$datadir" = "" ] ; then 12# options of postgresql.conf take effect)
20 datadir=$DEFAULT_DATA_DIR 13# This is normally controlled by the global default set by systemd
21else 14# StandardOutput=syslog
22 if [ ! -e $datadir/postgresql.conf ] ; then
23 if [ -e $DEFAULT_DATA_DIR/postgresql.conf -a -e $datadir ] ; then
24 ln -s $DEFAULT_DATA_DIR/*.conf $datadir/
25 fi
26 fi
27fi
28 15
29cd / 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
30 22
31start () 23# Maximum number of seconds pg_ctl will wait for postgres to start. Note that
32{ 24# PGSTARTTIMEOUT should be less than TimeoutSec value.
33 echo -n "Starting postgres server..." 25Environment=PGSTARTTIMEOUT=270
34 if pidof ${DAEMON} > /dev/null; then
35 echo "already running."
36 exit 0
37 fi
38 touch /var/log/postgresql.log
39 chown postgres /var/log/postgresql.log
40 sudo -u postgres /usr/bin/pg_ctl start -w -D $datadir -s -l /var/log/postgresql.log
41 if [ $? -eq 0 ]; then
42 echo "done."
43 else
44 echo "failed."
45 fi
46}
47 26
48stop () 27Environment=PGDATA=/usr/local/pgsql/data
49{
50 echo -n "Stopping postgres server..."
51 if ! pidof ${DAEMON} >/dev/null; then
52 echo "not running."
53 exit 0
54 fi
55 sudo -u postgres /usr/bin/pg_ctl stop -w -D $datadir -m fast -s
56 if [ $? -eq 0 ]; then
57 echo "done."
58 else
59 if [ -f $DEFAULT_DATA_DIR/postmaster.pid -a "$datadir" != "$DEFAULT_DATA_DIR" ] ; then
60 # Special case for transition
61 sudo -u postgres /usr/bin/pg_ctl stop -w -D $DEFAULT_DATA_DIR -m fast -s
62 fi
63 if ! pidof ${DAEMON} > /dev/null; then
64 echo "done."
65 else
66 echo "failed."
67 exit 1
68 fi
69 fi
70}
71 28
72case "$1" in
73 start)
74 start
75 ;;
76 stop)
77 stop
78 ;;
79 force-reload)
80 stop
81 start
82 ;;
83 restart)
84 stop
85 start
86 ;;
87 *)
88 echo "Usage: $0 {start|stop|force-reload|restart}"
89 exit 1
90 ;;
91esac
92 29
93exit 0 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-support/postgresql/postgresql/postgresql-init b/meta-openstack/recipes-support/postgresql/postgresql/postgresql-init
index f5e7dfb..cc7b13e 100644
--- a/meta-openstack/recipes-support/postgresql/postgresql/postgresql-init
+++ b/meta-openstack/recipes-support/postgresql/postgresql/postgresql-init
@@ -18,11 +18,14 @@ if [ -e $DATA_DIR/PG_VERSION ]; then
18 exit 0 18 exit 0
19fi 19fi
20 20
21# Create the DB
21sudo -u postgres initdb -D $DATA_DIR 22sudo -u postgres initdb -D $DATA_DIR
23
24# Allow readers/writers by IP
22echo "listen_addresses = '*'" >> $DATA_DIR/postgresql.conf 25echo "listen_addresses = '*'" >> $DATA_DIR/postgresql.conf
23echo "host all all ${CONTROLLER_IP}/32 trust" >> $DATA_DIR/pg_hba.conf 26echo "host all all ${CONTROLLER_IP}/32 trust" >> $DATA_DIR/pg_hba.conf
24echo "host all all ${COMPUTE_IP}/32 trust" >> $DATA_DIR/pg_hba.conf 27echo "host all all ${COMPUTE_IP}/32 trust" >> $DATA_DIR/pg_hba.conf
25/etc/init.d/postgresql start 28systemctl restart postgresql
26 29
27count=0 30count=0
28done=0 31done=0
@@ -30,9 +33,9 @@ while [ $count -le 10 ] && [ $done -eq 0 ]; do
30 sudo -u postgres psql -c "CREATE ROLE ${DB_USER} WITH SUPERUSER LOGIN PASSWORD '${DB_PASSWORD}'" 2> /dev/null 33 sudo -u postgres psql -c "CREATE ROLE ${DB_USER} WITH SUPERUSER LOGIN PASSWORD '${DB_PASSWORD}'" 2> /dev/null
31 if [ $? -ne 0 ]; then 34 if [ $? -ne 0 ]; then
32 echo "[INFO] postgres: failed to create account for ${DB_USER}, trying again" 35 echo "[INFO] postgres: failed to create account for ${DB_USER}, trying again"
33 /etc/init.d/postgresql stop 36 systemctl stop postresql
34 sleep 3 37 sleep 3
35 /etc/init.d/postgresql start 38 systemctl start postgresql
36 sleep 3 39 sleep 3
37 else 40 else
38 echo "[INFO] postgres: created account for ${DB_USER}, continuing .. " 41 echo "[INFO] postgres: created account for ${DB_USER}, continuing .. "
diff --git a/meta-openstack/recipes-support/postgresql/postgresql/postgresql-init.service b/meta-openstack/recipes-support/postgresql/postgresql/postgresql-init.service
new file mode 100644
index 0000000..94206d2
--- /dev/null
+++ b/meta-openstack/recipes-support/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-support/postgresql/postgresql_9.%.bbappend b/meta-openstack/recipes-support/postgresql/postgresql_9.%.bbappend
index b26054e..5b87960 100644
--- a/meta-openstack/recipes-support/postgresql/postgresql_9.%.bbappend
+++ b/meta-openstack/recipes-support/postgresql/postgresql_9.%.bbappend
@@ -1,57 +1,46 @@
1FILESEXTRAPATHS_prepend := "${THISDIR}/${PN}:" 1FILESEXTRAPATHS_prepend := "${THISDIR}/${PN}:"
2 2
3SRC_URI += "file://postgresql \ 3SRC_URI += " \
4 file://postgresql-init" 4 file://postgresql-init \
5 file://postgresql-init.service \
6 "
5 7
6inherit useradd update-rc.d identity hosts 8inherit identity hosts
7 9
8PACKAGECONFIG[libxml] = "--with-libxml CFLAGS=-I${STAGING_INCDIR}/libxml2,--without-libxml,libxml2,libxml2" 10SYSTEMD_AUTO_ENABLE_${PN} = "enable"
9 11
10# default 12# default
11DB_DATADIR ?= "/var/lib/postgres/data" 13DB_DATADIR ?= "/var/lib/postgres/data"
12 14
13do_install_append() { 15do_install_append() {
14 INIT_D_DEST_DIR=${D}${sysconfdir}/init.d 16 D_DEST_DIR=${D}${sysconfdir}/postgresql
15 17
16 install -d ${D}${sysconfdir}/init.d/ 18 install -d ${D_DEST_DIR}
17 install -m 0755 ${WORKDIR}/postgresql ${INIT_D_DEST_DIR}/postgresql 19 install -m 0755 ${WORKDIR}/postgresql-init ${D_DEST_DIR}/postgresql-init
18 install -m 0755 ${WORKDIR}/postgresql-init ${INIT_D_DEST_DIR}/postgresql-init
19 20
20 sed -e "s:%DB_DATADIR%:${DB_DATADIR}:g" -i ${INIT_D_DEST_DIR}/postgresql 21 sed -e "s:%DB_DATADIR%:${DB_DATADIR}:g" -i ${D_DEST_DIR}/postgresql-init
21 sed -e "s:%DB_DATADIR%:${DB_DATADIR}:g" -i ${INIT_D_DEST_DIR}/postgresql-init 22 sed -e "s:\(PGDATA=\).*$:\1${DB_DATADIR}:g" -i ${D}${systemd_unitdir}/system/postgresql.service
22 23
23 sed -e "s:%DB_USER%:${DB_USER}:g" -i ${INIT_D_DEST_DIR}/postgresql-init 24 sed -e "s:%DB_USER%:${DB_USER}:g" -i ${D_DEST_DIR}/postgresql-init
24 sed -e "s:%DB_PASSWORD%:${DB_PASSWORD}:g" -i ${INIT_D_DEST_DIR}/postgresql-init 25 sed -e "s:%DB_PASSWORD%:${DB_PASSWORD}:g" -i ${D_DEST_DIR}/postgresql-init
25 26
26 sed -e "s:%CONTROLLER_IP%:${CONTROLLER_IP}:g" -i ${INIT_D_DEST_DIR}/postgresql-init 27 sed -e "s:%CONTROLLER_IP%:${CONTROLLER_IP}:g" -i ${D_DEST_DIR}/postgresql-init
27 sed -e "s:%CONTROLLER_HOST%:${CONTROLLER_HOST}:g" -i ${INIT_D_DEST_DIR}/postgresql-init 28 sed -e "s:%CONTROLLER_HOST%:${CONTROLLER_HOST}:g" -i ${D_DEST_DIR}/postgresql-init
28 29
29 sed -e "s:%COMPUTE_IP%:${COMPUTE_IP}:g" -i ${INIT_D_DEST_DIR}/postgresql-init 30 sed -e "s:%COMPUTE_IP%:${COMPUTE_IP}:g" -i ${D_DEST_DIR}/postgresql-init
30 sed -e "s:%COMPUTE_HOST%:${COMPUTE_HOST}:g" -i ${INIT_D_DEST_DIR}/postgresql-init 31 sed -e "s:%COMPUTE_HOST%:${COMPUTE_HOST}:g" -i ${D_DEST_DIR}/postgresql-init
31}
32 32
33RDEPENDS_${PN} += "postgresql-timezone eglibc-utils update-rc.d" 33 install -d ${D}${systemd_unitdir}/system/
34USERADD_PACKAGES = "${PN}" 34 PG_INIT_SERVICE_FILE=${D}${systemd_unitdir}/system/postgresql-init.service
35GROUPADD_PARAM_${PN} = "--system postgres" 35 install -m 644 ${WORKDIR}/postgresql-init.service ${PG_INIT_SERVICE_FILE}
36USERADD_PARAM_${PN} = "--system --home /var/lib/postgres -g postgres \ 36 sed -e "s:%SYSCONFIGDIR%:${sysconfdir}:g" -i ${PG_INIT_SERVICE_FILE}
37 --no-create-home --shell /bin/false postgres" 37}
38 38
39PACKAGES += " ${PN}-setup" 39PACKAGES += " ${PN}-setup"
40ALLOW_EMPTY_${PN}-setup = "1"
41
42pkg_postinst_${PN}-setup () {
43 # postgres 9.2.4 postinst
44 if [ -z "$D" ]; then
45 /etc/init.d/postgresql-init
46 if [ $? -ne 0 ]; then
47 echo "[ERROR] postgres: unable to create admin account"
48 exit 1
49 fi
50 fi
51}
52 40
53FILES_${PN} += "${localstatedir}/run/${PN}" 41SYSTEMD_PACKAGES += "${PN}-setup"
42SYSTEMD_SERVICE_${PN}-setup = "postgresql-init.service"
54 43
55INITSCRIPT_PACKAGES = "${PN}" 44FILES_${PN}-setup = " \
56INITSCRIPT_NAME = "${PN}" 45 ${systemd_unitdir}/system \
57INITSCRIPT_PARAMS = "defaults" 46"