#!/bin/sh

# PostgreSQL boot time startup script for Darwin/Mac OS X. Copy this
# directory with all of its files to /Library/StartupItems.

# Created from the FreeBSD script by Peter Eisentraut (or so I'm
# guessing from the $id line in that freebsd startup script), which
# was in turn created through merger of the Linux start script by Ryan
# Kirkpatrick and the script in the FreeBSD ports collection. All
# other files in this bundle were adapted from the Apache startup
# bundle distributed with Mac OS X by Apple. Instructions for creating
# bundles may be found here:
#
#  http://www.opensource.apple.com/projects/documentation/howto/html/SystemStarter_HOWTO.html
#
# Localization of the message string is incomplete -- and likely
# inaccurate for many languages. Contributions welcome.


################################################################################
## EDIT FROM HERE
################################################################################

# Installation prefix
prefix=/usr/local/pgsql

# Data directory
PGDATA="/usr/local/pgsql/data"

# Who to run pg_ctl as, should be "postgres".
PGUSER=postgres

# Where to keep a log file
PGLOG="$PGDATA/serverlog"

################################################################################
## STOP EDITING HERE
################################################################################

# The path that is to be used for the script
PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin

# What to use to start up the postmaster
DAEMON="$prefix/bin/pg_ctl"

test -x "$DAEMON" || exit 0

. /etc/rc.common

case $1 in
    start)
	ConsoleMessage "Starting PostgreSQL"
	sudo -u $PGUSER $DAEMON start -D "$PGDATA" -s -l $PGLOG
	;;
    stop)
	sudo -u $PGUSER $DAEMON stop -D "$PGDATA" -s -m fast
	;;
    restart)
	sudo -u $PGUSER $DAEMON restart -D "$PGDATA" -s -m fast
	;;
    status)
	sudo -u $PGUSER $DAEMON status -D "$PGDATA"
	;;
    *)
	# Print help
	echo "Usage: `basename $0` {start|stop|restart|status}"
	Exit 1
	;;
esac

exit 0
