tor.sh.in 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. #!/bin/sh
  2. #
  3. #tor The Onion Router
  4. #
  5. #chkconfig:2345 90 10
  6. #description: Onion Router
  7. TORUSER=
  8. TORGROUP=
  9. TORBIN=@BINDIR@/tor
  10. TORPID=@LOCALSTATEDIR@/run/tor/tor.pid
  11. TORLOG=@LOCALSTATEDIR@/log/tor/tor.log
  12. TORCONF=@CONFDIR@/torrc
  13. # Strictly speaking, we don't need to su if we have --user and --group.
  14. # "Belt and suspenders," says jbash.
  15. TORARGS="--pidfile $TORPID --logfile $TORLOG --runasdaemon 1"
  16. if [ "x$TORUSER" != "x" ]; then
  17. TORARGS="$TORARGS --user $TORUSER"
  18. fi
  19. if [ "x$TORGROUP" != "x" ]; then
  20. TORARGS="$TORARGS --group $TORGROUP"
  21. fi
  22. RETVAL=0
  23. case "$1" in
  24. start)
  25. if [ -f $TORPID ]; then
  26. echo "tor appears to be already running (pid file exists)"
  27. echo "Maybe you should run: $0 restart ?"
  28. RETVAL=1
  29. else
  30. echo -n "Starting tor..."
  31. if [ "x$TORUSER" = "x" ]; then
  32. $TORBIN -f $TORCONF $TORARGS
  33. else
  34. /bin/su -c "$TORBIN -f $TORCONF $TORARGS" $TORUSER
  35. fi
  36. RETVAL=$?
  37. if [ $RETVAL -eq 0 ]; then
  38. echo " ok"
  39. else
  40. echo " ERROR!"
  41. fi
  42. fi
  43. ;;
  44. stop)
  45. if [ -f $TORPID ]; then
  46. echo -n "Killing tor..."
  47. kill `cat $TORPID`
  48. RETVAL=$?
  49. if [ $RETVAL -eq 0 ]; then
  50. echo " ok"
  51. else
  52. echo " ERROR!"
  53. fi
  54. else
  55. echo "Unable to kill tor: $TORPID does not exist"
  56. RETVAL=1
  57. fi
  58. ;;
  59. restart)
  60. $0 stop
  61. if [ -f $TORPID ]; then
  62. rm -f $TORPID
  63. fi
  64. $0 start
  65. ;;
  66. status)
  67. PID=`cat $TORPID 2>/dev/null`
  68. if [ "$PID" != "" ]; then
  69. torstat=`ps -p $PID | grep -c "^$PID"`
  70. if [ $torstat ]; then
  71. echo "tor is running ($PID)"
  72. else
  73. echo "tor is not running (looks like it crashed, look for core? $PID)"
  74. fi
  75. else
  76. echo "tor is not running (exited gracefully)"
  77. fi
  78. ;;
  79. log)
  80. cat $TORLOG
  81. ;;
  82. *)
  83. echo "Usage: $0 (start|stop|restart|status|log)"
  84. exit 1
  85. esac
  86. exit $RETVAL