tor.sh.in 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  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. reload)
  60. if [ -f $TORPID ]; then
  61. echo -n "Sending HUP to tor..."
  62. kill -HUP `cat $TORPID`
  63. RETVAL=$?
  64. if [ $RETVAL -eq 0 ]; then
  65. echo " ok"
  66. else
  67. echo " ERROR!"
  68. fi
  69. else
  70. echo "Unable to kill tor: $TORPID does not exist"
  71. RETVAL=1
  72. fi
  73. ;;
  74. restart)
  75. $0 stop
  76. if [ -f $TORPID ]; then
  77. rm -f $TORPID
  78. fi
  79. $0 start
  80. ;;
  81. status)
  82. PID=`cat $TORPID 2>/dev/null`
  83. if [ "$PID" != "" ]; then
  84. torstat=`ps -p $PID | grep -c "^$PID"`
  85. if [ $torstat ]; then
  86. echo "tor is running ($PID)"
  87. else
  88. echo "tor is not running (looks like it crashed, look for core? $PID)"
  89. fi
  90. else
  91. echo "tor is not running (exited gracefully)"
  92. fi
  93. ;;
  94. log)
  95. cat $TORLOG
  96. ;;
  97. *)
  98. echo "Usage: $0 (start|stop|restart|status|log)"
  99. exit 1
  100. esac
  101. exit $RETVAL