diff options
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 | ||