mirror of
https://github.com/wassname/docker-postgresql.git
synced 2026-06-28 04:37:52 +08:00
e0ce5c7005
Users should be able mount at volume at /var/run/postgresql so as to expose the postgresql unix socket.
55 lines
1.9 KiB
Bash
Executable File
55 lines
1.9 KiB
Bash
Executable File
#!/bin/bash
|
|
set -e
|
|
|
|
PG_VERSION="9.1"
|
|
PG_CONFDIR="/etc/postgresql/${PG_VERSION}/main"
|
|
PG_BINDIR="/usr/lib/postgresql/${PG_VERSION}/bin"
|
|
PG_DATADIR="/var/lib/postgresql/${PG_VERSION}/main"
|
|
|
|
# fix permissions and ownership of /var/lib/postgresql
|
|
chown -R postgres:postgres /var/lib/postgresql
|
|
chmod 700 /var/lib/postgresql
|
|
|
|
# fix permissions and ownership of /var/run/postgresql
|
|
chown -R postgres:postgres /var/run/postgresql
|
|
chmod 775 /var/run/postgresql
|
|
chmod g+s /var/run/postgresql
|
|
|
|
# disable ssl
|
|
sed 's/ssl = true/#ssl = true/' -i ${PG_CONFDIR}/postgresql.conf
|
|
|
|
# listen on all interfaces
|
|
cat >> ${PG_CONFDIR}/postgresql.conf <<EOF
|
|
listen_addresses = '*'
|
|
EOF
|
|
|
|
# allow remote connections to postgresql database
|
|
cat >> ${PG_CONFDIR}/pg_hba.conf <<EOF
|
|
host all all 0.0.0.0/0 md5
|
|
EOF
|
|
|
|
# initialize PostgreSQL data directory
|
|
if [ ! -d ${PG_DATADIR} ]; then
|
|
echo "Initializing database..."
|
|
PG_PASSWORD=$(pwgen -c -n -1 14)
|
|
echo "${PG_PASSWORD}" > /var/lib/postgresql/pwfile
|
|
sudo -u postgres -H "${PG_BINDIR}/initdb" \
|
|
--pgdata="${PG_DATADIR}" --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 ${PG_BINDIR}/postgres \
|
|
-D ${PG_DATADIR} -c config_file=${PG_CONFDIR}/postgresql.conf
|