Revise 0.2.1.17-rc changelog.
[tor.git] / contrib / osx / Tor
blob0660fd7c8d7fa4fbff2cdb229a69e39f4e53d3c7
1 #!/bin/sh
3 TORLOC=/Library/StartupItems/Tor/Tor.loc
5 if [ -f $TORLOC ]; then
6 TORDIR=`cat /Library/StartupItems/Tor/Tor.loc`
7 if [ "x$TORDIR" = "x" -o ! -d $TORDIR -o ! -x $TORDIR/tor ]; then
8 TORDIR=/Library/Tor
9 fi
10 else
11 TORDIR=/Library/Tor
13 TORCONF=$TORDIR/torrc
14 TORDATA=$TORDIR/var/lib/tor
15 TORPID=/var/run/Tor.pid
16 TORUSER=_tor
17 TORGROUP=daemon
18 TORCMD=$TORDIR/tor
19 TORLOG=/var/log/tor.log
21 ## Determine OSX Version
22 # map version to name
23 if [ -x /usr/bin/sw_vers ]; then
24 # This is poor, yet functional. We don't care about the 3rd number in
25 # the OS version
26 OSVER=`/usr/bin/sw_vers | grep ProductVersion | cut -f2 | cut -d"." -f1,2`
27 case "$OSVER" in
28 "10.6") ARCH="universal";;
29 "10.5") ARCH="universal";;
30 "10.4") ARCH="universal";;
31 "10.3") ARCH="ppc";;
32 "10.2") ARCH="ppc";;
33 "10.1") ARCH="ppc";;
34 "10.0") ARCH="ppc";;
35 esac
36 else
37 ARCH="unknown"
40 if [ $ARCH != "universal" ]; then
41 export EVENT_NOKQUEUE=1
45 # Tor Service
48 . /etc/rc.common
50 StartService ()
53 if [ -f $TORCMD ]; then
54 if pid=$(GetPID Tor); then
55 return 0
56 else
57 ConsoleMessage "Starting Tor Service"
58 # Tentative
59 # Making sure it is not running (I know it is not a best approarch)
60 killall tor 2>/dev/null
61 $TORCMD -f "$TORCONF" --runasdaemon 1 --pidfile "$TORPID" --datadirectory "$TORDATA" --user "$TORUSER" --group "$TORGROUP" --log "notice file $TORLOG" &
66 StopService ()
68 if pid=$(GetPID Tor); then
69 ConsoleMessage "Stopping Tor Service"
70 kill -TERM "${pid}"
71 # Just for sanity (sometimes necessary.)
72 killall tor 2>/dev/null
73 else
74 ConsoleMessage "Tor Service not responding."
75 # Just for sanity (sometimes necessary.)
76 killall tor 2>/dev/null
80 RestartService () { StopService; StartService; }
82 if [ "$#" = 0 ]; then
83 echo "Syntax: tor {start|stop}"
84 exit 1
85 fi
87 RunService "$1"