Files
docker-postgresql/start
T
2014-07-04 10:25:03 +05:30

46 lines
1.7 KiB
Bash
Executable File

#!/bin/bash
set -e
# fix permissions and ownership of /var/lib/postgresql
chown -R postgres:postgres /var/lib/postgresql
chmod 700 /var/lib/postgresql
# disable ssl
sed 's/ssl = true/#ssl = true/' -i /etc/postgresql/9.1/main/postgresql.conf
# listen on all interfaces
cat >> /etc/postgresql/9.1/main/postgresql.conf <<EOF
listen_addresses = '*'
EOF
# allow remote connections to postgresql database
cat >> /etc/postgresql/9.1/main/pg_hba.conf <<EOF
host all all 0.0.0.0/0 md5
EOF
# initialize PostgreSQL data directory
if [ ! -d /var/lib/postgresql/9.1/main ]; then
echo "Initializing database..."
PG_PASSWORD=$(pwgen -c -n -1 14)
echo "${PG_PASSWORD}" > /var/lib/postgresql/pwfile
sudo -u postgres -H /usr/lib/postgresql/9.1/bin/initdb \
--pgdata=/var/lib/postgresql/9.1/main --pwfile=/var/lib/postgresql/pwfile \
--username=postgres --encoding=unicode --auth=trust >/dev/null
fi
if [ -f /var/lib/postgresql/pwfile ]; then
PG_PASSWORD=$(cat /var/lib/postgresql/pwfile)
echo "|------------------------------------------------------------------|"
echo "| PostgreSQL User: postgres, Password: ${PG_PASSWORD} |"
echo "| |"
echo "| To remove the PostgreSQL login credentials from the logs, please |"
echo "| make a note of password and then delete the file pwfile |"
echo "| from the data store. |"
echo "|------------------------------------------------------------------|"
fi
echo "Starting PostgreSQL server..."
exec sudo -u postgres -H /usr/lib/postgresql/9.1/bin/postgres \
-D /var/lib/postgresql/9.1/main \
-c config_file=/etc/postgresql/9.1/main/postgresql.conf