tor.sh.in 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  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. TORDATA=@LOCALSTATEDIR@/lib/tor
  13. TORCONF=@CONFDIR@/torrc
  14. # Strictly speaking, we don't need to su if we have --user and --group.
  15. # "Belt and suspenders," says jbash.
  16. TORARGS="--pidfile $TORPID --log \"notice file $TORLOG \" --runasdaemon 1 --datadirectory $TORDATA"
  17. if [ "x$TORUSER" != "x" ]; then
  18. TORARGS="$TORARGS --user $TORUSER"
  19. fi
  20. if [ "x$TORGROUP" != "x" ]; then
  21. TORARGS="$TORARGS --group $TORGROUP"
  22. fi
  23. RETVAL=0
  24. case "$1" in
  25. start)
  26. if [ -f $TORPID ]; then
  27. echo "tor appears to be already running (pid file exists)"
  28. echo "Maybe you should run: $0 restart ?"
  29. RETVAL=1
  30. else
  31. echo -n "Starting tor..."
  32. if [ "x$TORUSER" = "x" ]; then
  33. $TORBIN -f $TORCONF $TORARGS
  34. else
  35. /bin/su -c "$TORBIN -f $TORCONF $TORARGS" $TORUSER
  36. fi
  37. RETVAL=$?
  38. if [ $RETVAL -eq 0 ]; then
  39. echo " ok"
  40. else
  41. echo " ERROR!"
  42. fi
  43. fi
  44. ;;
  45. stop)
  46. if [ -f $TORPID ]; then
  47. echo -n "Killing tor..."
  48. kill `cat $TORPID`
  49. RETVAL=$?
  50. if [ $RETVAL -eq 0 ]; then
  51. echo " ok"
  52. else
  53. echo " ERROR!"
  54. fi
  55. else
  56. echo "Unable to kill tor: $TORPID does not exist. Assuming already dead."
  57. RETVAL=0
  58. fi
  59. ;;
  60. reload)
  61. if [ -f $TORPID ]; then
  62. echo -n "Sending HUP to tor..."
  63. kill -HUP `cat $TORPID`
  64. RETVAL=$?
  65. if [ $RETVAL -eq 0 ]; then
  66. echo " ok"
  67. else
  68. echo " ERROR!"
  69. fi
  70. else
  71. echo "Unable to kill tor: $TORPID does not exist"
  72. RETVAL=1
  73. fi
  74. ;;
  75. restart)
  76. $0 stop
  77. if [ -f $TORPID ]; then
  78. rm -f $TORPID
  79. fi
  80. $0 start
  81. ;;
  82. status)
  83. PID=`cat $TORPID 2>/dev/null`
  84. if [ "$PID" != "" ]; then
  85. torstat=`ps -p $PID | grep -c "^$PID"`
  86. if [ $torstat ]; then
  87. echo "tor is running ($PID)"
  88. else
  89. echo "tor is not running (looks like it crashed, look for core? $PID)"
  90. fi
  91. else
  92. echo "tor is not running (exited gracefully)"
  93. fi
  94. ;;
  95. log)
  96. cat $TORLOG
  97. ;;
  98. *)
  99. echo "Usage: $0 (start|stop|restart|status|log)"
  100. exit 1
  101. esac
  102. exit $RETVAL