#!/bin/sh

# PROVIDE: prayer
# REQUIRE: LOGIN
#
# Add the following lines to /etc/rc.conf.local or /etc/rc.conf
# to enable this service:
#
# prayer_enable (bool): Set to NO by default.
# prayer_chrooted (bool): Set to NO by default.
#	Force prayer to be executed in chrooted
# prayer_prefork (bool): Set to NO by default.
# 	Allow prayer to prefork itself at startup
# 

. /etc/rc.subr

name="prayer"
rcvar=prayer_enable

command=/usr/local/sbin/${name}
pidfile="/var/spool/prayer/pid/${name}.pid"

start_precmd="prayer_prestart"
stop_postcmd="prayer_poststop"

load_rc_config $name

: ${prayer_enable="NO"}
: ${prayer_chrooted="NO"}
: ${prayer_prefork="NO"}

prayer_prestart()
{
	if checkyesno prayer_enable; then
		if checkyesno prayer_chrooted; then	
			echo "Chroot no fully functionnal for now so not activated"
		#	command=/usr/local/sbin/${name}-chroot
		fi
		if ! checkyesno prayer_prefork; then
			command_args="--disable-prefork"
		fi
	fi
	return 0
}

prayer_poststop()
{
	kill -15 `head -1 /var/spool/prayer/pid/${name}-session.pid` 
}

run_rc_command "$1"
