#!/bin/sh
#
# $NetBSD: tor.in,v 1.3 2008/12/21 11:10:27 obache Exp $
#
# PROVIDE: tor
# REQUIRE: DAEMON
# KEYWORD: shutdown
#
# You will need to set some variables in /etc/rc.conf to start tor:
#
# tor=YES

if [ -f /etc/rc.subr ]
then
	. /etc/rc.subr
fi

name="tor"
rcvar=$name
command="/usr/pkg/bin/tor"
required_files="/usr/pkg/etc/tor/torrc"
start_cmd="tor_start"
stop_cmd="tor_stop"
pidfile="/var/chroot/tor/${name}.pid"
restart_cmd="tor_stop ; tor_start"

tor_start ()
{
	${command} --User tor --RunAsDaemon 1 \
		--DataDirectory /var/chroot/tor --PIDFile ${pidfile}
}

tor_stop()
{
	kill `cat ${pidfile}` 2>/dev/null
}

if [ -f /etc/rc.subr -a -f /etc/rc.conf -a -d /etc/rc.d -a -f /etc/rc.d/DAEMON ]
then
	load_rc_config $name
	run_rc_command "$1"
else
	eval ${start_cmd}
fi
