#!/usr/bin/sh

# PostgreSQL boot time startup script for FreeBSD.  Copy this file to
# /usr/local/etc/rc.d/postgresql.

# Created through merger of the Linux start script by Ryan Kirkpatrick
# and the script in the FreeBSD ports collection.

# $PostgreSQL: pgsql/contrib/start-scripts/freebsd,v 1.4 2004/10/01 18:30:21 tgl Exp $

. /etc/profile

bindir=`pg_config | grep BINDIR | cut -f 3 -d ' '`
if [ "$bindir" = "" ]; then
  echo "failed to get postgresql bin directory"
  exit 1
fi

PGHOST="/var/run/postgresql"
PGUSER=postgres
export PGPORT=9984

if [ -x /sbin/runuser ]
then
    SU=/sbin/runuser
else
    SU=su
fi

case $1 in
    start)
	chmod 777 /var/run/postgresql
	$SU -l postgres -c "$bindir/pg_ctl -w -o '-k /var/run/postgresql' -D /quadstor/pgsqlsys/data/ -o '-p 9984' -l /quadstor/pgsqlsys/pg.log start"
	;;
    stop)
	$SU -l postgres -c "$bindir/pg_ctl -w -o '-k /var/run/postgresql' -D /quadstor/pgsqlsys/data/ -o '-p 9984' -l /quadstor/pgsqlsys/pg.log stop"
	;;
    restart)
    	stop
	start
	;;
    status)
	$SU -l postgres -c "$bindir/pg_isready -p 9984"
	;;
    *)
	# Print help
	echo "Usage: `basename $0` {start|stop|restart|status}" 1>&2
	exit 1
	;;
esac

exit 0
