tor.sh.in 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. #! /bin/sh
  2. TORBIN=@BINDIR@/tor
  3. TORPID=@LOCALSTATEDIR@/run/tor.pid
  4. TORLOG=@LOCALSTATEDIR@/log/tor/tor.log
  5. TORCONF=@CONFDIR@/torrc
  6. RETVAL=0
  7. case "$1" in
  8. start)
  9. if [ -f $TORPID ]; then
  10. echo "tor appears to be already running (pid file exists)"
  11. echo "Maybe you should run: $0 restart ?"
  12. RETVAL=1
  13. else
  14. echo -n "Starting tor..."
  15. $TORBIN -f $TORCONF -l warning >$TORLOG 2>&1 &
  16. RETVAL=$?
  17. if [ $RETVAL -eq 0 ]; then
  18. echo " ok"
  19. else
  20. echo " ERROR!"
  21. fi
  22. fi
  23. ;;
  24. stop)
  25. if [ -f $TORPID ]; then
  26. echo -n "Killing tor..."
  27. kill `cat $TORPID`
  28. RETVAL=$?
  29. if [ $RETVAL -eq 0 ]; then
  30. echo " ok"
  31. else
  32. echo " ERROR!"
  33. fi
  34. else
  35. echo "Unable to kill tor: $TORPID does not exist"
  36. RETVAL=1
  37. fi
  38. ;;
  39. restart)
  40. $0 stop
  41. if [ -f $TORPID ]; then
  42. rm -f $TORPID
  43. fi
  44. $0 start
  45. ;;
  46. status)
  47. PID=`cat $TORPID 2>/dev/null`
  48. if [ "$PID" != "" ]; then
  49. torstat=`ps -p $PID | grep -c "^$PID"`
  50. if [ $torstat ]; then
  51. echo "tor is running ($PID)"
  52. else
  53. echo "tor is not running (looks like it crashed, look for core? $PID)"
  54. fi
  55. else
  56. echo "tor is not running (exited gracefully)"
  57. fi
  58. ;;
  59. log)
  60. cat $TORLOG
  61. ;;
  62. *)
  63. echo "Usage: $0 (start|stop|restart|status|log)"
  64. exit 1
  65. esac
  66. exit $RETVAL