#!/bin/sh
#
# MacPorts generated daemondo support script
#

#
# Init
#
prefix=/opt/local

#
# Start
#
Start()
{
	[ -f "/opt/local/etc/tor/torrc" ] \
		&& /opt/local/bin/tor \
			-f /opt/local/etc/tor/torrc 2>/dev/null
}

#
# Stop
#
Stop()
{
	if [ -f "/opt/local/var/run/tor/tor.pid" ]; then
		kill `cat /opt/local/var/run/tor/tor.pid` \
			&& rm -f /opt/local/var/run/tor/tor.pid
	else
		/usr/bin/killall -SIGUSR1 tor 2>/dev/null
	fi
}

#
# Restart
#
Restart()
{
	Stop
	Start
}

#
# Run
#
Run()
{
case $1 in
  start  ) Start   ;;
  stop   ) Stop    ;;
  restart) Restart ;;
  *      ) echo "$0: unknown argument: $1";;
esac
}

#
# Run a phase based on the selector
#
Run $1

