tor.sh.in 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  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. if [ -x /bin/su ] ; then
  25. SUPROG=/bin/su
  26. elif [ -x /sbin/su ] ; then
  27. SUPROG=/sbin/su
  28. elif [ -x /usr/bin/su ] ; then
  29. SUPROG=/usr/bin/su
  30. elif [ -x /usr/sbin/su ] ; then
  31. SUPROG=/usr/sbin/su
  32. else
  33. SUPROG=/bin/su
  34. fi
  35. case "$1" in
  36. start)
  37. if [ -f $TORPID ]; then
  38. echo "tor appears to be already running (pid file exists)"
  39. echo "Maybe you should run: $0 restart ?"
  40. RETVAL=1
  41. else
  42. echo -n "Starting tor..."
  43. if [ "x$TORUSER" = "x" ]; then
  44. $TORBIN -f $TORCONF $TORARGS
  45. else
  46. $SUPROG -c "$TORBIN -f $TORCONF $TORARGS" $TORUSER
  47. fi
  48. RETVAL=$?
  49. if [ $RETVAL -eq 0 ]; then
  50. echo " ok"
  51. else
  52. echo " ERROR!"
  53. fi
  54. fi
  55. ;;
  56. stop)
  57. if [ -f $TORPID ]; then
  58. echo -n "Killing tor..."
  59. kill `cat $TORPID`
  60. RETVAL=$?
  61. if [ $RETVAL -eq 0 ]; then
  62. echo " ok"
  63. else
  64. echo " ERROR!"
  65. fi
  66. else
  67. echo "Unable to kill tor: $TORPID does not exist. Assuming already dead."
  68. RETVAL=0
  69. fi
  70. ;;
  71. reload)
  72. if [ -f $TORPID ]; then
  73. echo -n "Sending HUP to tor..."
  74. kill -HUP `cat $TORPID`
  75. RETVAL=$?
  76. if [ $RETVAL -eq 0 ]; then
  77. echo " ok"
  78. else
  79. echo " ERROR!"
  80. fi
  81. else
  82. echo "Unable to kill tor: $TORPID does not exist"
  83. RETVAL=1
  84. fi
  85. ;;
  86. restart)
  87. $0 stop
  88. if [ -f $TORPID ]; then
  89. rm -f $TORPID
  90. fi
  91. $0 start
  92. ;;
  93. status)
  94. PID=`cat $TORPID 2>/dev/null`
  95. if [ "$PID" != "" ]; then
  96. torstat=`ps -p $PID | grep -c "^$PID"`
  97. if [ $torstat ]; then
  98. echo "tor is running ($PID)"
  99. else
  100. echo "tor is not running (looks like it crashed, look for core? $PID)"
  101. fi
  102. else
  103. echo "tor is not running (exited gracefully)"
  104. fi
  105. ;;
  106. log)
  107. cat $TORLOG
  108. ;;
  109. *)
  110. echo "Usage: $0 (start|stop|restart|status|log)"
  111. exit 1
  112. esac
  113. exit $RETVAL