# postgresql
#
# starts postgresql

description	"Start PostrgeSQL"
author		"Arjan Bouter <abouter@sourcemage.org>"

start on mounted-remotefs
stop on shutdown or network-stop

expect daemon

script
  . /etc/sysconfig/postgresql
  cd "$DBPATH" &&
  if [[ ! -z $PORT ]]; then
    PGPORT="-o -p $PORT"
  fi &&
  if [[ ! -z $LOGFILE ]]; then
    PGLOG="-l $LOGFILE"
  fi &&
  su $USER -s /bin/sh -c "pg_ctl start -D $DBPATH -s $PGLOG $PGPORT"
end script

pre-stop script
  . /etc/sysconfig/postgresql
  cd "$DBPATH" &&
  su $USER -s /bin/sh -c "pg_ctl stop -D $DBPATH -m fast"
end script
