Tor 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. #!/bin/sh
  2. export EVENT_NOKQUEUE=1 # assume kqueue broken on all os x machines for now.
  3. TORLOC=/Library/StartupItems/Tor/Tor.loc
  4. if [ -f $TORLOC ]; then
  5. TORDIR=`cat /Library/StartupItems/Tor/Tor.loc`
  6. if [ "x$TORDIR" = "x" -o ! -d $TORDIR -o ! -x $TORDIR/tor ]; then
  7. TORDIR=/Library/Tor
  8. fi
  9. else
  10. TORDIR=/Library/Tor
  11. fi
  12. TORCONF=$TORDIR/torrc
  13. TORDATA=$TORDIR/var/lib/tor
  14. TORPID=/var/run/Tor.pid
  15. TORUSER=_tor
  16. TORGROUP=daemon
  17. TORCMD=$TORDIR/tor
  18. TORLOG=/var/log/tor/tor.log
  19. ##
  20. # Tor Service
  21. ##
  22. . /etc/rc.common
  23. StartService ()
  24. {
  25. if [ -f $TORCMD ]; then
  26. if pid=$(GetPID Tor); then
  27. return 0
  28. else
  29. ConsoleMessage "Starting Tor Service"
  30. # Tentative
  31. # Making sure it is not running (I know it is not a best approarch)
  32. killall tor 2>/dev/null
  33. $TORCMD -f "$TORCONF" --runasdaemon 1 --pidfile "$TORPID" --datadirectory "$TORDATA" --user "$TORUSER" --group "$TORGROUP" --log "notice file $TORLOG" &
  34. fi
  35. fi
  36. }
  37. StopService ()
  38. {
  39. if pid=$(GetPID Tor); then
  40. ConsoleMessage "Stopping Tor Service"
  41. kill -TERM "${pid}"
  42. # Just for sanity (sometimes necessary.)
  43. killall tor 2>/dev/null
  44. else
  45. ConsoleMessage "Tor Service not responding."
  46. # Just for sanity (sometimes necessary.)
  47. killall tor 2>/dev/null
  48. fi
  49. }
  50. RestartService () { StopService; StartService; }
  51. if [ "x$1" = x ]; then
  52. echo "Syntax: tor {start|stop}"
  53. exit 1
  54. fi
  55. RunService "$1"