#!/bin/sh

# PROVIDE: foundationdb
# REQUIRE: LOGIN
# BEFORE:  securelevel
# KEYWORD: shutdown

# Add the following line to /etc/rc.conf to enable `foundationdb':
#
#foundationdb_enable="YES"
#
# Define config file here to run with different config file:
#
#foundationdb_config="xxxxx"
#

. /etc/rc.subr

name="foundationdb"
rcvar="${name}_enable"

load_rc_config "$name"

: ${foundationdb_enable="NO"}
: ${foundationdb_user="%%FOUNDATIONDB_USER%%"}
: ${foundationdb_group="%%FOUNDATIONDB_GROUP%%"}
: ${foundationdb_config="%%PREFIX%%/etc/foundationdb/foundationdb.conf"}

start_precmd="foundationdb_start_precmd"

pidfile="/var/run/fdbmonitor.pid"
command=%%PREFIX%%/sbin/fdbmonitor
command_args="--conffile ${foundationdb_config} --lockfile ${pidfile} --daemonize"

foundationdb_start_precmd()
{
	if [ ! -e "${pidfile}" ]; then
		install -m 0600 -o "${foundationdb_user}" -g "${foundationdb_group}" /dev/null "${pidfile}"
	fi
}

run_rc_command $1
