summaryrefslogtreecommitdiff
path: root/testing/postgresql/postgresql-initdb
diff options
context:
space:
mode:
authorroot <root@rshg054.dnsready.net>2012-08-19 00:04:07 +0000
committerroot <root@rshg054.dnsready.net>2012-08-19 00:04:07 +0000
commitc512f9eb344575ac6bce0b13729c05e1760cd094 (patch)
tree8d60a9bd559a941bba52a67170900c159d2024eb /testing/postgresql/postgresql-initdb
parent948da5eabcbf8d74270e661d0730ba1c203913f5 (diff)
Sun Aug 19 00:04:07 UTC 2012
Diffstat (limited to 'testing/postgresql/postgresql-initdb')
-rwxr-xr-xtesting/postgresql/postgresql-initdb33
1 files changed, 33 insertions, 0 deletions
diff --git a/testing/postgresql/postgresql-initdb b/testing/postgresql/postgresql-initdb
new file mode 100755
index 000000000..a691a83ff
--- /dev/null
+++ b/testing/postgresql/postgresql-initdb
@@ -0,0 +1,33 @@
+#!/bin/sh
+
+set -e
+
+. /etc/conf.d/postgresql
+
+# 2nd clause is necessary to prevent symlinking the directory to itself when it
+# doesn't exist yet
+if [ ! /var/lib/postgres -ef "$PGROOT" ] && [ /var/lib/postgres != "$PGROOT" ]; then
+ echo "Creating symlink /var/lib/postgres -> $PGROOT"
+
+ # Remove /var/lib/postgres if empty dir, but not if symlink
+ if [ ! -L /var/lib/postgres ] && [ -d /var/lib/postgres ]; then
+ rmdir /var/lib/postgres
+ fi
+
+ ln -sf "$PGROOT" /var/lib/postgres
+fi
+
+PGDATA="$PGROOT/data"
+
+if [ ! -d "$PGDATA" ]; then
+ echo "Initializing database in $PGDATA"
+
+ mkdir -p "$PGDATA"
+ chown -R postgres:postgres "$PGDATA"
+
+ su - postgres -m -c "/usr/bin/initdb $INITOPTS -D '$PGDATA'" >/dev/null
+
+ if [ -f /etc/postgresql/postgresql.conf ]; then
+ ln -sf /etc/postgresql/postgresql.conf "$PGDATA/postgresql.conf"
+ fi
+fi