Spotter-VM/postgres.sh

24 lines
901 B
Bash
Raw Normal View History

#!/bin/sh
SOURCE_DIR=$(realpath $(dirname "${0}"))/postgres
# Build Docker container
docker build -t postgres ${SOURCE_DIR}
cp ${SOURCE_DIR}/etc/init.d/postgres /etc/init.d/postgres
rc-update -u
# Create Postgres instance
2018-01-27 14:44:44 +01:00
mkdir -p /srv/postgres/data
chown -R 5432:5432 /srv/postgres/data
chmod 700 /srv/postgres/data
docker run --rm --name postgres -h postgres -v /srv/postgres/data:/var/lib/postgresql postgres initdb -D /var/lib/postgresql
# Configure Postgres
2018-01-27 14:44:44 +01:00
cp ${SOURCE_DIR}/srv/postgres/data/postgresql.conf /srv/postgres/data/postgresql.conf
cp ${SOURCE_DIR}/srv/postgres/data/pg_hba.conf /srv/postgres/data/pg_hba.conf
# Enable query logging. Only if the DEBUG environment variable is set
if [ ${DEBUG:-0} -eq 1 ]; then
2018-01-27 14:44:44 +01:00
sed -i 's/^#log_destination/log_destination/' /srv/postgres/data/postgresql.conf
sed -i 's/^#log_statement/log_statement/' /srv/postgres/data/postgresql.conf
fi