diff options
author | Bruce Ashfield <bruce.ashfield@windriver.com> | 2013-09-15 21:53:35 -0400 |
---|---|---|
committer | Bruce Ashfield <bruce.ashfield@windriver.com> | 2013-10-03 01:15:42 -0400 |
commit | f6a914b542f228488b66de6f6bd3dfb361e5a728 (patch) | |
tree | c952c0433d802bbe6cb33357aa83b636f2474a8c /meta-openstack/recipes-support/postgresql | |
parent | 645ced2601e0e55e1d9ff391855f3d917188a53d (diff) | |
download | meta-cloud-services-f6a914b542f228488b66de6f6bd3dfb361e5a728.tar.gz |
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>
Diffstat (limited to 'meta-openstack/recipes-support/postgresql')
-rw-r--r-- | meta-openstack/recipes-support/postgresql/postgresql_9.2.4.bbappend | 27 |
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 98e7207..f131e21 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 \ | |||
19 | --no-create-home --shell /bin/false postgres" | 19 | --no-create-home --shell /bin/false postgres" |
20 | 20 | ||
21 | pkg_postinst_${PN} () { | 21 | pkg_postinst_${PN} () { |
22 | # postgres 9.2.4 postinst | ||
22 | if [ "x$D" != "x" ]; then | 23 | if [ "x$D" != "x" ]; then |
23 | exit 1 | 24 | exit 1 |
24 | fi | 25 | fi |
25 | 26 | ||
26 | sudo -u postgres initdb -D /etc/${PN}/ | 27 | sudo -u postgres initdb -D /etc/${PN}/ |
28 | sleep 2 | ||
27 | /etc/init.d/postgresql start | 29 | /etc/init.d/postgresql start |
28 | sudo -u postgres psql -c "CREATE ROLE ${DB_USER} WITH SUPERUSER LOGIN PASSWORD '${DB_PASSWORD}'" | 30 | sleep 5 |
31 | |||
32 | count=0 | ||
33 | done=0 | ||
34 | while [ $count -le 10 ] && [ $done -eq 0 ]; do | ||
35 | sudo -u postgres psql -c "CREATE ROLE ${DB_USER} WITH SUPERUSER LOGIN PASSWORD '${DB_PASSWORD}'" 2> /dev/null | ||
36 | if [ $? -ne 0 ]; then | ||
37 | echo "[INFO] postgres: failed to create account for ${DB_USER}, trying again" | ||
38 | /etc/init.d/postgresql stop | ||
39 | sleep 2 | ||
40 | /etc/init.d/postgresql start | ||
41 | sleep 1 | ||
42 | else | ||
43 | done=1 | ||
44 | fi | ||
45 | count=`expr $count + 1` | ||
46 | done | ||
47 | |||
48 | if [ $done -eq 0 ]; then | ||
49 | echo "[ERROR] postgres: unable to create admin account" | ||
50 | exit 1 | ||
51 | fi | ||
52 | |||
29 | ln -s /usr/share/zoneinfo /usr/share/postgresql/timezone | 53 | ln -s /usr/share/zoneinfo /usr/share/postgresql/timezone |
54 | # end postgres 9.2.4 postinst | ||
30 | } | 55 | } |
31 | 56 | ||
32 | FILES_${PN} += "${localstatedir}/run/${PN}" | 57 | FILES_${PN} += "${localstatedir}/run/${PN}" |