aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBruce Ashfield <bruce.ashfield@windriver.com>2013-09-15 21:53:35 -0400
committerBruce Ashfield <bruce.ashfield@windriver.com>2013-10-03 01:15:42 -0400
commitf6a914b542f228488b66de6f6bd3dfb361e5a728 (patch)
treec952c0433d802bbe6cb33357aa83b636f2474a8c
parent645ced2601e0e55e1d9ff391855f3d917188a53d (diff)
downloadmeta-cloud-services-f6a914b542f228488b66de6f6bd3dfb361e5a728.tar.gz
meta-cloud-services-f6a914b542f228488b66de6f6bd3dfb361e5a728.tar.bz2
meta-cloud-services-f6a914b542f228488b66de6f6bd3dfb361e5a728.zip
postgresql: fix slow database startup errors
On some targets postgresql's server processes start slowly. If they haven't started and the admin account or other operations are attempted, they fail with a message about not being able to communicate to the local server. If postgres is not properly setup, then subsequent components will also fail, since they either cannot talk to the server, or can't use the 'admin' account. To fix this issue, we add additional sleep states, and attempt to create the admin role 10 times, with a delay between each attempt. If we fail to contact the server after 10 attempts, a clear message is displayed and the postinst returns a failing return code. Signed-off-by: Bruce Ashfield <bruce.ashfield@windriver.com>
-rw-r--r--meta-openstack/recipes-support/postgresql/postgresql_9.2.4.bbappend27
1 files changed, 26 insertions, 1 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 98e7207c..f131e213 100644
--- a/meta-openstack/recipes-support/postgresql/postgresql_9.2.4.bbappend
+++ b/meta-openstack/recipes-support/postgresql/postgresql_9.2.4.bbappend
@@ -19,14 +19,39 @@ USERADD_PARAM_${PN} = "--system --home /var/lib/postgres -g postgres \
--no-create-home --shell /bin/false postgres"
pkg_postinst_${PN} () {
+ # postgres 9.2.4 postinst
if [ "x$D" != "x" ]; then
exit 1
fi
sudo -u postgres initdb -D /etc/${PN}/
+ sleep 2
/etc/init.d/postgresql start
- sudo -u postgres psql -c "CREATE ROLE ${DB_USER} WITH SUPERUSER LOGIN PASSWORD '${DB_PASSWORD}'"
+ sleep 5
+
+ count=0
+ done=0
+ while [ $count -le 10 ] && [ $done -eq 0 ]; do
+ sudo -u postgres psql -c "CREATE ROLE ${DB_USER} WITH SUPERUSER LOGIN PASSWORD '${DB_PASSWORD}'" 2> /dev/null
+ if [ $? -ne 0 ]; then
+ echo "[INFO] postgres: failed to create account for ${DB_USER}, trying again"
+ /etc/init.d/postgresql stop
+ sleep 2
+ /etc/init.d/postgresql start
+ sleep 1
+ else
+ done=1
+ fi
+ count=`expr $count + 1`
+ done
+
+ if [ $done -eq 0 ]; then
+ echo "[ERROR] postgres: unable to create admin account"
+ exit 1
+ fi
+
ln -s /usr/share/zoneinfo /usr/share/postgresql/timezone
+ # end postgres 9.2.4 postinst
}
FILES_${PN} += "${localstatedir}/run/${PN}"