Tor 950 B

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