Tor 1.2 KB

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