#!/bin/bash

PROGRAM=/usr/bin/postgres
RUNLEVEL=3
NEEDS="+remote_fs"

. /etc/init.d/smgl_init
. /etc/sysconfig/postgresql

start()
{
  echo "Starting postmaster..."
  cd "$DBPATH" &&
  if [[ ! -z "$PORT" ]]; then
    PGPORT="-p $PORT"
  fi &&
  if [[ $LOGFILE ]]; then
    PGLOG="-l $LOGFILE"
  fi &&
  su $USER -s /bin/sh -c "pg_ctl start -D $DBPATH $PGLOG -o '$PGPORT'"
  evaluate_retval
}

stop()
{
  echo "Stopping postmaster..."
  cd "$DBPATH" &&
  su $USER -s /bin/sh -c "pg_ctl stop -D $DBPATH -m fast"
  evaluate_retval
}

reload()
{
  echo "Reloading postmaster configuration..."
  cd "$DBPATH" &&
  su $USER -s /bin/sh -c "pg_ctl reload -D $DBPATH"
  evaluate_retval
}
