#!/bin/sh

# $FreeBSD: ports/databases/postgresql7/files/pgsql.sh.tmpl,v 1.12 2001/05/02 11:44:38 olgeni Exp $
#
# For postmaster startup options, edit $PGDATA/postgresql.conf

PGDATA=/pgsql/data01
PGBIN=/usr/local/bin

case $1 in
start)
    [ -d /usr/local/lib ] && /sbin/ldconfig -m /usr/local/lib
    [ -x ${PGBIN}/pg_ctl ] && {
	su -l postgres -c \
	    "[ -d ${PGDATA} ] && exec ${PGBIN}/pg_ctl -o -i -w -l ~postgres/errlog -D ${PGDATA} start"
	echo -n ' postgres'
    }
    ;;

stop)
    [ -x ${PGBIN}/pg_ctl ] && {
	su -l postgres -c 'exec ${PGBIN}/pg_ctl stop -s -m smart'
	echo -n ' postgres'
    }
    ;;

status)
    [ -x ${PGBIN}/pg_ctl ] && {
	exec su -l postgres -c 'exec ${PGBIN}/pg_ctl status'
    }
    ;;

*)
    echo "usage: `basename $0` {start|stop|status}" >&2
    exit 64
    ;;
esac
