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/postgresql/postgresql-init | |
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/postgresql/postgresql-init')
-rw-r--r-- | meta-openstack/recipes-support/postgresql/postgresql/postgresql-init | 46 |
1 files changed, 46 insertions, 0 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 | ||