29 lines
963 B
Bash
29 lines
963 B
Bash
#!/bin/bash
|
|
|
|
SOURCE_DIR=$(realpath $(dirname "${0}"))/postgres
|
|
|
|
# Build Docker container
|
|
docker build -t postgres ${SOURCE_DIR}
|
|
|
|
# Create Postgres instance
|
|
mkdir /srv/postgres
|
|
chown -R 5432:5432 /srv/postgres
|
|
chmod 700 /srv/postgres
|
|
docker run --rm --name postgres -v /srv/postgres:/var/lib/postgresql postgres initdb -D /var/lib/postgresql
|
|
|
|
# Configure Postgres
|
|
cp ${SOURCE_DIR}/srv/postgres/postgresql.conf /srv/postgres/postgresql.conf
|
|
cp ${SOURCE_DIR}/srv/postgres/pg_hba.conf /srv/postgres/pg_hba.conf
|
|
|
|
# Enable query logging. Only if the DEBUG environment variable is set
|
|
if [ ${DEBUG:-0} -eq 1 ]; then
|
|
sed -i 's/^#log_destination/log_destination/' /srv/postgres/postgresql.conf
|
|
sed -i 's/^#log_statement/log_statement/' /srv/postgres/postgresql.conf
|
|
fi
|
|
|
|
# Configure Postgres service
|
|
cp ${SOURCE_DIR}/lib/systemd/system/postgres.service /lib/systemd/system/postgres.service
|
|
systemctl daemon-reload
|
|
systemctl enable postgres
|
|
systemctl start postgres
|