summaryrefslogtreecommitdiff
path: root/contrib/osx/Tor
blob: 0752b85c5886a6db411a5b76f06a6c4e61cb5e32 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
#!/bin/sh

TORCONF=/Library/Tor/torrc
TORDIR=/Library/Tor/var/lib/tor
TORPID=/var/run/Tor.pid
TORUSER=_tor
TORGROUP=daemon
TORCMD=/Library/Tor/tor

##
# Tor Service
##

. /etc/rc.common

StartService ()
{

    if [ -f $TORCMD ]; then
        if pid=$(GetPID Tor); then
            return 0
        else
		ConsoleMessage "Starting Tor Service"
# Tentative
# Making sure it is not running (I know it is not a best approarch)
		killall tor 2>/dev/null
		$TORCMD -f $TORCONF --runasdaemon 1 --pidfile $TORPID --datadirectory $TORDIR --user $TORUSER --group $TORGROUP &
	fi
    fi
}

StopService ()
{
    if pid=$(GetPID Tor); then
	ConsoleMessage "Stopping Tor Service"
	kill -TERM "${pid}"
# Just for sanity (sometimes necessary.)
	killall tor 2>/dev/null
    else
	ConsoleMessage "Tor Service not responding."
# Just for sanity (sometimes necessary.)
	killall tor 2>/dev/null
    fi
}

RestartService () { StopService; StartService; }

RunService "$1"