#! /bin/sh

# PROVIDE: tox_bootstrapd
# REQUIRE: NETWORKING DAEMON
# KEYWORD: shutdown

# Add the following line to /etc/rc.conf to enable `tox-bootstrapd':
#
#tox_bootstrapd_enable="YES"
#

. /etc/rc.subr

name="tox_bootstrapd"
rcvar=tox_bootstrapd_enable

# read settings, set default values
load_rc_config "${name}"
: ${tox_bootstrapd_enable="NO"}

required_files=${tox_bootstrapd_config:="/usr/local/etc/tox-bootstrapd.conf"}
_pidprefix="/var/run/tox-bootstrapd"
pidfile=${tox_bootstrapd_pidfile:="$_pidprefix/tox-bootstrapd.pid"}
long_name="Tox DHT bootstrap daemon."
tox_bootstrapd_user="toxdht"
command="/usr/local/bin/tox-bootstrapd"
command_args="--config ${tox_bootstrapd_config}"

stop_cmd=${name}_stop

# Cannot use the regular stop() because the daemon forks
tox_bootstrapd_stop() {
	[ -f $pidfile ] || (echo "$name not running?"; exit 1)
	echo "Stopping $long_name"
	kill `ps ax | grep $command | grep -v grep | awk '{print $1}'`
	rm -f $pidfile
}

run_rc_command "$1"
