#!/bin/sh
#
# $FreeBSD: ports/databases/pgcluster/files/pgcluster.in,v 1.2 2007/07/26 16:05:04 rafan Exp $
#
# PROVIDE: pgcluster
# REQUIRE: DAEMON
# BEFORE:  pgreplicate
#
# Add the following line to /etc/rc.conf to enable pgcluster:
#
# pgcluster_enable="YES"
# # optional
# pgcluster_data="/home/pgsql/data"
# pgcluster_flags="-w -s"
#

. /etc/rc.subr

name="pgcluster"
rcvar=`set_rcvar`

command=/usr/local/bin/pg_ctl

load_rc_config ${name}

: ${pgcluster_enable="NO"}
: ${pgcluster_data="/usr/local/pgsql/data"}
: ${pgcluster_flags="-w -s"}

pgcluster_user=pgsql
pgcluster_flags="${pgcluster_flags} -D ${pgcluster_data}"
pidfile="${pgcluster_data}/postmaster.pid"

extra_commands="initdb recover"

initdb_cmd="pgcluster_initdb"
recover_cmd="pgcluster_recover"
start_cmd="pgcluster_start"
stop_cmd="pgcluster_stop"

pgcluster_start()
{
    su -m ${pgcluster_user} -c "exec ${command} start ${pgcluster_flags} -o '-i'"
}
pgcluster_stop()
{
    su -m ${pgcluster_user} -c "exec ${command} stop ${pgcluster_flags} -m i"
}
pgcluster_recover()
{
    su -m ${pgcluster_user} -c "exec ${command} start ${pgcluster_flags} -o '-i -R'"
}
pgcluster_initdb()
{
    su -m ${pgcluster_user} -c "exec /usr/local/bin/initdb -D ${pgcluster_data}"
}

run_rc_command "$1"
