summaryrefslogtreecommitdiffstats
path: root/meta-openstack/recipes-support/postgresql/postgresql/postgresql-init
diff options
context:
space:
mode:
Diffstat (limited to 'meta-openstack/recipes-support/postgresql/postgresql/postgresql-init')
-rw-r--r--meta-openstack/recipes-support/postgresql/postgresql/postgresql-init46
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
4PN=postgresql
5CONTROLLER_IP=%CONTROLLER_IP%
6COMPUTE_IP=%COMPUTE_IP%
7DB_USER=%DB_USER%
8DB_PASSWORD=%DB_PASSWORD%
9
10if [ -e /etc/${PN}/PG_VERSION ]; then
11 # the database has already been initialized, return
12 exit 0
13fi
14
15sudo -u postgres initdb -D /etc/${PN}/
16sleep 2
17echo "listen_addresses = '*'" >> /etc/${PN}/postgresql.conf
18echo "host all all ${CONTROLLER_IP}/32 trust" >> /etc/${PN}/pg_hba.conf
19echo "host all all ${COMPUTE_IP}/32 trust" >> /etc/${PN}/pg_hba.conf
20sleep 2
21/etc/init.d/postgresql start
22sleep 10
23
24count=0
25done=0
26while [ $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`
39done
40
41if [ $done -eq 0 ]; then
42 echo "[ERROR] postgres: unable to create admin account"
43 exit 1
44fi
45
46ln -s /usr/share/zoneinfo /usr/share/postgresql/timezone