diff options
| author | Bruce Ashfield <bruce.ashfield@windriver.com> | 2013-10-04 00:27:53 -0400 |
|---|---|---|
| committer | Bruce Ashfield <bruce.ashfield@windriver.com> | 2013-10-04 13:16:33 -0400 |
| commit | 608fa75973c111c61cf55e99cf3172ff3f3f00b1 (patch) | |
| tree | fa3b3a3d457dc1daafdefa5c100379bcf3de1928 /meta-openstack/recipes-support/postgresql | |
| parent | 6806482a7ba6f020b0cff44b2b797eede2b702af (diff) | |
| download | meta-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')
| -rw-r--r-- | meta-openstack/recipes-support/postgresql/postgresql/postgresql-init | 46 | ||||
| -rw-r--r-- | meta-openstack/recipes-support/postgresql/postgresql_9.2.4.bbappend | 46 |
2 files changed, 62 insertions, 30 deletions
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 | |||
| 4 | PN=postgresql | ||
| 5 | CONTROLLER_IP=%CONTROLLER_IP% | ||
| 6 | COMPUTE_IP=%COMPUTE_IP% | ||
| 7 | DB_USER=%DB_USER% | ||
| 8 | DB_PASSWORD=%DB_PASSWORD% | ||
| 9 | |||
| 10 | if [ -e /etc/${PN}/PG_VERSION ]; then | ||
| 11 | # the database has already been initialized, return | ||
| 12 | exit 0 | ||
| 13 | fi | ||
| 14 | |||
| 15 | sudo -u postgres initdb -D /etc/${PN}/ | ||
| 16 | sleep 2 | ||
| 17 | echo "listen_addresses = '*'" >> /etc/${PN}/postgresql.conf | ||
| 18 | echo "host all all ${CONTROLLER_IP}/32 trust" >> /etc/${PN}/pg_hba.conf | ||
| 19 | echo "host all all ${COMPUTE_IP}/32 trust" >> /etc/${PN}/pg_hba.conf | ||
| 20 | sleep 2 | ||
| 21 | /etc/init.d/postgresql start | ||
| 22 | sleep 10 | ||
| 23 | |||
| 24 | count=0 | ||
| 25 | done=0 | ||
| 26 | while [ $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` | ||
| 39 | done | ||
| 40 | |||
| 41 | if [ $done -eq 0 ]; then | ||
| 42 | echo "[ERROR] postgres: unable to create admin account" | ||
| 43 | exit 1 | ||
| 44 | fi | ||
| 45 | |||
| 46 | ln -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 @@ | |||
| 1 | FILESEXTRAPATHS_prepend := "${THISDIR}/${PN}:" | 1 | FILESEXTRAPATHS_prepend := "${THISDIR}/${PN}:" |
| 2 | PRINC := "${@int(PRINC) + 1}" | 2 | PRINC := "${@int(PRINC) + 1}" |
| 3 | 3 | ||
| 4 | SRC_URI += "file://postgresql" | 4 | SRC_URI += "file://postgresql \ |
| 5 | file://postgresql-init" | ||
| 5 | 6 | ||
| 6 | inherit useradd update-rc.d identity hosts | 7 | inherit 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 | ||
| 16 | USERADD_PACKAGES = "${PN}" | 29 | USERADD_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 | ||
| 61 | FILES_${PN} += "${localstatedir}/run/${PN}" | 47 | FILES_${PN} += "${localstatedir}/run/${PN}" |
