#!/bin/sh
#
# DarwinPorts generated StartupItem
#

. /etc/rc.common

PGDATA=${PGDATA:='/opt/local/var/db/pgsql/defaultdb'}
if [ ! -d ${PGDATA} ]; then
    ConsoleMessage "Error starting PostgreSQL-8: PGDATA directory '$PGDATA' doesn't exist!"
    exit 1
fi

StartService ()
{
	if [ "${POSTGRESQL8:=-NO-}" = "-YES-" ]; then
		ConsoleMessage "Starting PostgreSQL-8"
		su -l postgres -c "exec /opt/local/bin/pg_ctl start -D $PGDATA -s -w"
	fi
}

StopService ()
{
		ConsoleMessage "Stopping PostgreSQL-8"
		su -l postgres -c "exec /opt/local/bin/pg_ctl stop -D $PGDATA -s -m fast"
}

RestartService ()
{
	if [ "${POSTGRESQL8:=-NO-}" = "-YES-" ]; then
		ConsoleMessage "Restarting PostgreSQL-8"
		su -l postgres -c "exec /opt/local/bin/pg_ctl restart -D $PGDATA -s -m fast"
	fi
}

RunService "$1"
