#!/bin/sh
#
# $FreeBSD: ports/net/boinc-client/files/boinc.sh.in,v 1.6 2010/03/27 00:13:38 dougb Exp $

# PROVIDE: boinc
# REQUIRE: LOGIN
# KEYWORD: shutdown

. /etc/rc.subr

name="boinc"
rcvar=`set_rcvar`

boinc_user=boinc
boinc_home=/var/db/boinc
boinc_flags="--dir ${boinc_home}"
program_file=boinc_client
program_path=/usr/local/bin/${program_file}
syslog_facility=daemon.err

load_rc_config $name
: ${boinc_enable="NO"}

start_cmd=boinc_start
stop_cmd=boinc_stop

boinc_start() {
	if checkyesno boinc_enable
	then
		if [ ! -x ${program_path} ]
		then
			logger -sp ${syslog_facility} -t ${program_file} \
				"unable to start: ${program_path} is missing."
			exit 72
		fi
		if ps axo ucomm | egrep ${program_file}; then
			logger -sp ${syslog_facility} -t ${program_file} \
			"unable to start: ${program_file} is already running."
			exit 72
		fi
		echo "Starting BOINC client."
		idprio 31 su - ${boinc_user} -c "${program_path} ${boinc_flags} >/dev/null &"
	fi
}

boinc_stop() {
	killall ${program_file} 2> /dev/null
}

run_rc_command "$1"
