Tor 1006 B

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