tor.sh.in 1.5 KB

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