mirror of
https://github.com/wassname/docker-postgresql.git
synced 2026-08-19 12:10:28 +08:00
defined macros for path variables
This commit is contained in:
@@ -1,30 +1,35 @@
|
|||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
set -e
|
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
|
# fix permissions and ownership of /var/lib/postgresql
|
||||||
chown -R postgres:postgres /var/lib/postgresql
|
chown -R postgres:postgres /var/lib/postgresql
|
||||||
chmod 700 /var/lib/postgresql
|
chmod 700 /var/lib/postgresql
|
||||||
|
|
||||||
# disable ssl
|
# disable ssl
|
||||||
sed 's/ssl = true/#ssl = true/' -i /etc/postgresql/9.1/main/postgresql.conf
|
sed 's/ssl = true/#ssl = true/' -i ${PG_CONFDIR}/postgresql.conf
|
||||||
|
|
||||||
# listen on all interfaces
|
# listen on all interfaces
|
||||||
cat >> /etc/postgresql/9.1/main/postgresql.conf <<EOF
|
cat >> ${PG_CONFDIR}/postgresql.conf <<EOF
|
||||||
listen_addresses = '*'
|
listen_addresses = '*'
|
||||||
EOF
|
EOF
|
||||||
|
|
||||||
# allow remote connections to postgresql database
|
# allow remote connections to postgresql database
|
||||||
cat >> /etc/postgresql/9.1/main/pg_hba.conf <<EOF
|
cat >> ${PG_CONFDIR}/pg_hba.conf <<EOF
|
||||||
host all all 0.0.0.0/0 md5
|
host all all 0.0.0.0/0 md5
|
||||||
EOF
|
EOF
|
||||||
|
|
||||||
# initialize PostgreSQL data directory
|
# initialize PostgreSQL data directory
|
||||||
if [ ! -d /var/lib/postgresql/9.1/main ]; then
|
if [ ! -d ${PG_DATADIR} ]; then
|
||||||
echo "Initializing database..."
|
echo "Initializing database..."
|
||||||
PG_PASSWORD=$(pwgen -c -n -1 14)
|
PG_PASSWORD=$(pwgen -c -n -1 14)
|
||||||
echo "${PG_PASSWORD}" > /var/lib/postgresql/pwfile
|
echo "${PG_PASSWORD}" > /var/lib/postgresql/pwfile
|
||||||
sudo -u postgres -H /usr/lib/postgresql/9.1/bin/initdb \
|
sudo -u postgres -H "${PG_BINDIR}/initdb" \
|
||||||
--pgdata=/var/lib/postgresql/9.1/main --pwfile=/var/lib/postgresql/pwfile \
|
--pgdata="${PG_DATADIR}" --pwfile=/var/lib/postgresql/pwfile \
|
||||||
--username=postgres --encoding=unicode --auth=trust >/dev/null
|
--username=postgres --encoding=unicode --auth=trust >/dev/null
|
||||||
fi
|
fi
|
||||||
|
|
||||||
@@ -40,6 +45,5 @@ if [ -f /var/lib/postgresql/pwfile ]; then
|
|||||||
fi
|
fi
|
||||||
|
|
||||||
echo "Starting PostgreSQL server..."
|
echo "Starting PostgreSQL server..."
|
||||||
exec sudo -u postgres -H /usr/lib/postgresql/9.1/bin/postgres \
|
exec sudo -u postgres -H ${PG_BINDIR}/postgres \
|
||||||
-D /var/lib/postgresql/9.1/main \
|
-D ${PG_DATADIR} -c config_file=${PG_CONFDIR}/postgresql.conf
|
||||||
-c config_file=/etc/postgresql/9.1/main/postgresql.conf
|
|
||||||
|
|||||||
Reference in New Issue
Block a user