summaryrefslogtreecommitdiffstats
path: root/meta-openstack/recipes-support/postgresql/postgresql_9.2.4.bbappend
diff options
context:
space:
mode:
authorBruce Ashfield <bruce.ashfield@windriver.com>2013-10-04 00:27:53 -0400
committerBruce Ashfield <bruce.ashfield@windriver.com>2013-10-04 13:16:33 -0400
commit608fa75973c111c61cf55e99cf3172ff3f3f00b1 (patch)
treefa3b3a3d457dc1daafdefa5c100379bcf3de1928 /meta-openstack/recipes-support/postgresql/postgresql_9.2.4.bbappend
parent6806482a7ba6f020b0cff44b2b797eede2b702af (diff)
downloadmeta-cloud-services-608fa75973c111c61cf55e99cf3172ff3f3f00b1.tar.gz
postgresql: unify startup and initialization
Since we can't count on package postinst order, many components check for a configured postgresql daemon, and if not found, initialize it. Rather than sprinkling the knowledge of how to initialize the database through all these packages, we create a more robust, central postgresql-init script, and call it when any component needs the database configured. Signed-off-by: Bruce Ashfield <bruce.ashfield@windriver.com>
Diffstat (limited to 'meta-openstack/recipes-support/postgresql/postgresql_9.2.4.bbappend')
-rw-r--r--meta-openstack/recipes-support/postgresql/postgresql_9.2.4.bbappend46
1 files changed, 16 insertions, 30 deletions
diff --git a/meta-openstack/recipes-support/postgresql/postgresql_9.2.4.bbappend b/meta-openstack/recipes-support/postgresql/postgresql_9.2.4.bbappend
index 7c28fa1..3174e94 100644
--- a/meta-openstack/recipes-support/postgresql/postgresql_9.2.4.bbappend
+++ b/meta-openstack/recipes-support/postgresql/postgresql_9.2.4.bbappend
@@ -1,7 +1,8 @@
1FILESEXTRAPATHS_prepend := "${THISDIR}/${PN}:" 1FILESEXTRAPATHS_prepend := "${THISDIR}/${PN}:"
2PRINC := "${@int(PRINC) + 1}" 2PRINC := "${@int(PRINC) + 1}"
3 3
4SRC_URI += "file://postgresql" 4SRC_URI += "file://postgresql \
5 file://postgresql-init"
5 6
6inherit useradd update-rc.d identity hosts 7inherit useradd update-rc.d identity hosts
7 8
@@ -11,6 +12,18 @@ do_install_append() {
11 12
12 install -d ${D}${sysconfdir}/init.d/ 13 install -d ${D}${sysconfdir}/init.d/
13 install -m 0755 ${WORKDIR}/postgresql ${D}${sysconfdir}/init.d/postgresql 14 install -m 0755 ${WORKDIR}/postgresql ${D}${sysconfdir}/init.d/postgresql
15
16 sed -e "s:%DB_USER%:${DB_USER}:g" -i ${WORKDIR}/postgresql-init
17 sed -e "s:%DB_PASSWORD%:${DB_PASSWORD}:g" -i ${WORKDIR}/postgresql-init
18
19 sed -e "s:%CONTROLLER_IP%:${CONTROLLER_IP}:g" -i ${WORKDIR}/postgresql-init
20 sed -e "s:%CONTROLLER_HOST%:${CONTROLLER_HOST}:g" -i ${WORKDIR}/postgresql-init
21
22 sed -e "s:%COMPUTE_IP%:${COMPUTE_IP}:g" -i ${WORKDIR}/postgresql-init
23 sed -e "s:%COMPUTE_HOST%:${COMPUTE_HOST}:g" -i ${WORKDIR}/postgresql-init
24
25 install -m 0755 ${WORKDIR}/postgresql-init ${D}${sysconfdir}/init.d/postgresql-init
26
14} 27}
15 28
16USERADD_PACKAGES = "${PN}" 29USERADD_PACKAGES = "${PN}"
@@ -24,38 +37,11 @@ pkg_postinst_${PN} () {
24 exit 1 37 exit 1
25 fi 38 fi
26 39
27 sudo -u postgres initdb -D /etc/${PN}/ 40 /etc/init.d/postgresql-init
28 sleep 2 41 if [ $? -eq 0 ]; then
29 echo "listen_addresses = '*'" >> /etc/${PN}/postgresql.conf
30 echo "host all all ${CONTROLLER_IP}/32 trust" >> /etc/${PN}/pg_hba.conf
31 echo "host all all ${COMPUTE_IP}/32 trust" >> /etc/${PN}/pg_hba.conf
32 sleep 2
33 /etc/init.d/postgresql start
34 sleep 5
35
36 count=0
37 done=0
38 while [ $count -le 10 ] && [ $done -eq 0 ]; do
39 sudo -u postgres psql -c "CREATE ROLE ${DB_USER} WITH SUPERUSER LOGIN PASSWORD '${DB_PASSWORD}'" 2> /dev/null
40 if [ $? -ne 0 ]; then
41 echo "[INFO] postgres: failed to create account for ${DB_USER}, trying again"
42 /etc/init.d/postgresql stop
43 sleep 2
44 /etc/init.d/postgresql start
45 sleep 1
46 else
47 done=1
48 fi
49 count=`expr $count + 1`
50 done
51
52 if [ $done -eq 0 ]; then
53 echo "[ERROR] postgres: unable to create admin account" 42 echo "[ERROR] postgres: unable to create admin account"
54 exit 1 43 exit 1
55 fi 44 fi
56
57 ln -s /usr/share/zoneinfo /usr/share/postgresql/timezone
58 # end postgres 9.2.4 postinst
59} 45}
60 46
61FILES_${PN} += "${localstatedir}/run/${PN}" 47FILES_${PN} += "${localstatedir}/run/${PN}"