summaryrefslogtreecommitdiffstats
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
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>
-rw-r--r--meta-openstack-qemu/recipes-devtools/python/python-nova-controller_2013.1.3.bbappend11
-rw-r--r--meta-openstack-qemu/recipes-devtools/python/python-nova_2013.1.3.bbappend (renamed from meta-openstack-qemu/recipes-devtools/python/python-nova-compute_2013.1.3.bbappend)0
-rw-r--r--meta-openstack/recipes-devtools/python/python-cinder_2013.1.3.bb4
-rw-r--r--meta-openstack/recipes-devtools/python/python-glance_2013.1.3.bb5
-rw-r--r--meta-openstack/recipes-devtools/python/python-keystone_2013.1.3.bb4
-rw-r--r--meta-openstack/recipes-devtools/python/python-nova_2013.1.3.bb13
-rw-r--r--meta-openstack/recipes-devtools/python/python-quantum_2013.1.3.bb5
-rw-r--r--meta-openstack/recipes-support/postgresql/postgresql/postgresql-init46
-rw-r--r--meta-openstack/recipes-support/postgresql/postgresql_9.2.4.bbappend46
9 files changed, 76 insertions, 58 deletions
diff --git a/meta-openstack-qemu/recipes-devtools/python/python-nova-controller_2013.1.3.bbappend b/meta-openstack-qemu/recipes-devtools/python/python-nova-controller_2013.1.3.bbappend
deleted file mode 100644
index f45a02b..0000000
--- a/meta-openstack-qemu/recipes-devtools/python/python-nova-controller_2013.1.3.bbappend
+++ /dev/null
@@ -1,11 +0,0 @@
1do_install_append() {
2 if [ ! -f "${WORKDIR}/nova.conf" ]; then
3 return
4 fi
5
6 TEMPLATE_CONF_DIR=${S}${sysconfdir}/${SRCNAME}
7 NOVA_CONF_DIR=${D}/${sysconfdir}/nova
8
9 sed -e "s:^libvirt_type.*=.*$:libvirt_type = qemu:" \
10 -i ${NOVA_CONF_DIR}/nova.conf
11} \ No newline at end of file
diff --git a/meta-openstack-qemu/recipes-devtools/python/python-nova-compute_2013.1.3.bbappend b/meta-openstack-qemu/recipes-devtools/python/python-nova_2013.1.3.bbappend
index 45f4307..45f4307 100644
--- a/meta-openstack-qemu/recipes-devtools/python/python-nova-compute_2013.1.3.bbappend
+++ b/meta-openstack-qemu/recipes-devtools/python/python-nova_2013.1.3.bbappend
diff --git a/meta-openstack/recipes-devtools/python/python-cinder_2013.1.3.bb b/meta-openstack/recipes-devtools/python/python-cinder_2013.1.3.bb
index 1cdcd98..a6a10e5 100644
--- a/meta-openstack/recipes-devtools/python/python-cinder_2013.1.3.bb
+++ b/meta-openstack/recipes-devtools/python/python-cinder_2013.1.3.bb
@@ -57,10 +57,8 @@ pkg_postinst_${SRCNAME} () {
57 57
58 # This is to make sure postgres is configured and running 58 # This is to make sure postgres is configured and running
59 if ! pidof postmaster > /dev/null; then 59 if ! pidof postmaster > /dev/null; then
60 sudo -u postgres initdb -D /etc/postgresql/ 60 /etc/init.d/postgresql-init
61 /etc/init.d/postgresql start 61 /etc/init.d/postgresql start
62 sleep 0.2
63 sudo -u postgres psql -c "CREATE ROLE ${DB_USER} WITH SUPERUSER LOGIN PASSWORD '${DB_PASSWORD}'"
64 fi 62 fi
65 63
66 sudo -u postgres createdb cinder 64 sudo -u postgres createdb cinder
diff --git a/meta-openstack/recipes-devtools/python/python-glance_2013.1.3.bb b/meta-openstack/recipes-devtools/python/python-glance_2013.1.3.bb
index 9bfd262..ff81a0c 100644
--- a/meta-openstack/recipes-devtools/python/python-glance_2013.1.3.bb
+++ b/meta-openstack/recipes-devtools/python/python-glance_2013.1.3.bb
@@ -65,10 +65,9 @@ pkg_postinst_${SRCNAME} () {
65 65
66 # This is to make sure postgres is configured and running 66 # This is to make sure postgres is configured and running
67 if ! pidof postmaster > /dev/null; then 67 if ! pidof postmaster > /dev/null; then
68 sudo -u postgres initdb -D /etc/postgresql/ 68 /etc/init.d/postgresql-init
69 /etc/init.d/postgresql start 69 /etc/init.d/postgresql start
70 sleep 0.2 70 sleep 5
71 sudo -u postgres psql -c "CREATE ROLE ${DB_USER} WITH SUPERUSER LOGIN PASSWORD '${DB_PASSWORD}'"
72 fi 71 fi
73 72
74 mkdir /var/log/glance 73 mkdir /var/log/glance
diff --git a/meta-openstack/recipes-devtools/python/python-keystone_2013.1.3.bb b/meta-openstack/recipes-devtools/python/python-keystone_2013.1.3.bb
index e124583..387fa68 100644
--- a/meta-openstack/recipes-devtools/python/python-keystone_2013.1.3.bb
+++ b/meta-openstack/recipes-devtools/python/python-keystone_2013.1.3.bb
@@ -58,11 +58,9 @@ pkg_postinst_${SRCNAME} () {
58 58
59 # This is to make sure postgres is configured and running 59 # This is to make sure postgres is configured and running
60 if ! pidof postmaster > /dev/null; then 60 if ! pidof postmaster > /dev/null; then
61 sudo -u postgres initdb -D /etc/postgresql/ 61 /etc/init.d/postgresql-init
62 sleep 10
63 /etc/init.d/postgresql start 62 /etc/init.d/postgresql start
64 sleep 5 63 sleep 5
65 sudo -u postgres psql -c "CREATE ROLE ${DB_USER} WITH SUPERUSER LOGIN PASSWORD '${DB_PASSWORD}'"
66 fi 64 fi
67 65
68 sudo -u postgres createdb keystone 66 sudo -u postgres createdb keystone
diff --git a/meta-openstack/recipes-devtools/python/python-nova_2013.1.3.bb b/meta-openstack/recipes-devtools/python/python-nova_2013.1.3.bb
index c2dd1f3..3552592 100644
--- a/meta-openstack/recipes-devtools/python/python-nova_2013.1.3.bb
+++ b/meta-openstack/recipes-devtools/python/python-nova_2013.1.3.bb
@@ -16,6 +16,7 @@ SRC_URI = "https://launchpad.net/${SRCNAME}/grizzly/${PV}/+download/${SRCNAME}-$
16 " 16 "
17 17
18SRC_URI += "file://nova-all \ 18SRC_URI += "file://nova-all \
19 file://nova-compute \
19 file://nova-consoleauth \ 20 file://nova-consoleauth \
20 file://nova-novncproxy \ 21 file://nova-novncproxy \
21 file://nova.conf \ 22 file://nova.conf \
@@ -93,6 +94,7 @@ do_install_append() {
93 if ${@base_contains('DISTRO_FEATURES', 'sysvinit', 'true', 'false', d)}; then 94 if ${@base_contains('DISTRO_FEATURES', 'sysvinit', 'true', 'false', d)}; then
94 install -d ${D}${sysconfdir}/init.d 95 install -d ${D}${sysconfdir}/init.d
95 install -m 0755 ${WORKDIR}/nova-all ${D}${sysconfdir}/init.d/nova-all 96 install -m 0755 ${WORKDIR}/nova-all ${D}${sysconfdir}/init.d/nova-all
97 install -m 0755 ${WORKDIR}/nova-compute ${D}${sysconfdir}/init.d/nova-compute
96 install -m 0755 ${WORKDIR}/nova-consoleauth ${D}${sysconfdir}/init.d/nova-consoleauth 98 install -m 0755 ${WORKDIR}/nova-consoleauth ${D}${sysconfdir}/init.d/nova-consoleauth
97 install -m 0755 ${WORKDIR}/nova-novncproxy ${D}${sysconfdir}/init.d/nova-novncproxy 99 install -m 0755 ${WORKDIR}/nova-novncproxy ${D}${sysconfdir}/init.d/nova-novncproxy
98 fi 100 fi
@@ -197,14 +199,15 @@ RDEPENDS_${SRCNAME}-common = "${PN} openssl openssl-misc libxml2 libxslt \
197 iptables curl dnsmasq sudo procps" 199 iptables curl dnsmasq sudo procps"
198 200
199RDEPENDS_${SRCNAME}-controller = "${PN} ${SRCNAME}-common \ 201RDEPENDS_${SRCNAME}-controller = "${PN} ${SRCNAME}-common \
200 ${SRCNAME}-consoleauth \ 202 ${SRCNAME}-consoleauth \
201 ${SRCNAME}-novncproxy \ 203 ${SRCNAME}-novncproxy \
202 postgresql postgresql-client python-psycopg2" 204 postgresql postgresql-client python-psycopg2"
203 205
204RDEPENDS_${SRCNAME}-compute = "${PN} ${SRCNAME}-common \ 206RDEPENDS_${SRCNAME}-compute = "${PN} ${SRCNAME}-common \
205 qemu libvirt libvirt-libvirtd libvirt-python libvirt-virsh" 207 qemu libvirt libvirt-libvirtd libvirt-python libvirt-virsh"
206 208
207INITSCRIPT_PACKAGES = "${SRCNAME}-controller ${SRCNAME}-consoleauth ${SRCNAME}-novncproxy" 209INITSCRIPT_PACKAGES = "${SRCNAME}-compute ${SRCNAME}-controller ${SRCNAME}-consoleauth ${SRCNAME}-novncproxy"
208INITSCRIPT_NAME_${SRCNAME}-controller = "nova-all" 210INITSCRIPT_NAME_${SRCNAME}-controller = "nova-all"
211INITSCRIPT_NAME_${SRCNAME}-compute = "nova-compute"
209INITSCRIPT_NAME_${SRCNAME}-consoleauth = "nova-consoleauth" 212INITSCRIPT_NAME_${SRCNAME}-consoleauth = "nova-consoleauth"
210INITSCRIPT_NAME_${SRCNAME}-novncproxy = "nova-novncproxy" 213INITSCRIPT_NAME_${SRCNAME}-novncproxy = "nova-novncproxy"
diff --git a/meta-openstack/recipes-devtools/python/python-quantum_2013.1.3.bb b/meta-openstack/recipes-devtools/python/python-quantum_2013.1.3.bb
index 34da3c9..8198e6a 100644
--- a/meta-openstack/recipes-devtools/python/python-quantum_2013.1.3.bb
+++ b/meta-openstack/recipes-devtools/python/python-quantum_2013.1.3.bb
@@ -74,10 +74,9 @@ pkg_postinst_${SRCNAME} () {
74 74
75 # This is to make sure postgres is configured and running 75 # This is to make sure postgres is configured and running
76 if ! pidof postmaster > /dev/null; then 76 if ! pidof postmaster > /dev/null; then
77 sudo -u postgres initdb -D /etc/postgresql/ 77 /etc/init.d/postgresql-init
78 /etc/init.d/postgresql start 78 /etc/init.d/postgresql start
79 sleep 0.2 79 sleep 5
80 sudo -u postgres psql -c "CREATE ROLE ${DB_USER} WITH SUPERUSER LOGIN PASSWORD '${DB_PASSWORD}'"
81 fi 80 fi
82 81
83 sudo -u postgres createdb ovs_quantum 82 sudo -u postgres createdb ovs_quantum
diff --git a/meta-openstack/recipes-support/postgresql/postgresql/postgresql-init b/meta-openstack/recipes-support/postgresql/postgresql/postgresql-init
new file mode 100644
index 0000000..d9850da
--- /dev/null
+++ b/meta-openstack/recipes-support/postgresql/postgresql/postgresql-init
@@ -0,0 +1,46 @@
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%
9
10if [ -e /etc/${PN}/PG_VERSION ]; then
11 # the database has already been initialized, return
12 exit 0
13fi
14
15sudo -u postgres initdb -D /etc/${PN}/
16sleep 2
17echo "listen_addresses = '*'" >> /etc/${PN}/postgresql.conf
18echo "host all all ${CONTROLLER_IP}/32 trust" >> /etc/${PN}/pg_hba.conf
19echo "host all all ${COMPUTE_IP}/32 trust" >> /etc/${PN}/pg_hba.conf
20sleep 2
21/etc/init.d/postgresql start
22sleep 10
23
24count=0
25done=0
26while [ $count -le 10 ] && [ $done -eq 0 ]; do
27 sudo -u postgres psql -c "CREATE ROLE ${DB_USER} WITH SUPERUSER LOGIN PASSWORD '${DB_PASSWORD}'" 2> /dev/null
28 if [ $? -ne 0 ]; then
29 echo "[INFO] postgres: failed to create account for ${DB_USER}, trying again"
30 /etc/init.d/postgresql stop
31 sleep 3
32 /etc/init.d/postgresql start
33 sleep 3
34 else
35 echo "[INFO] postgres: created account for ${DB_USER}, continuing .. "
36 done=1
37 fi
38 count=`expr $count + 1`
39done
40
41if [ $done -eq 0 ]; then
42 echo "[ERROR] postgres: unable to create admin account"
43 exit 1
44fi
45
46ln -s /usr/share/zoneinfo /usr/share/postgresql/timezone
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}"