#!/bin/bash

X=__META_PREFIX__
D=__META_DATADIR__

# This part will only work if this script is executed as superuser.
#
LOGDIR=/var/log/postgresql
mkdir -p $LOGDIR
chown -R postgres.postgres $LOGDIR/ 2> /dev/null

PG_CTL="PATH=$X/bin:$PATH pg_ctl"
LOG1=$LOGDIR/postgres.log
LOG2=$LOGDIR/pg_ctl.log

su postgres -c \
    "$PG_CTL stop -D $D -m fast -w -l $LOG1 2>&1 >> $LOG2"
sleep 3
killall -qw --signal SIGTERM postgres
