tor.sh.in 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. #!/bin/sh
  2. #
  3. # tor The Onion Router
  4. #
  5. # Startup/shutdown script for tor. This is a wrapper around torctl;
  6. # torctl does the actual work in a relatively system-independent, or at least
  7. # distribution-independent, way, and this script deals with fitting the
  8. # whole thing into the conventions of the particular system at hand.
  9. # This particular script is written for Red Hat/Fedora Linux, and may
  10. # also work on Mandrake, but not SuSE.
  11. #
  12. # These next couple of lines "declare" tor for the "chkconfig" program,
  13. # originally from SGI, used on Red Hat/Fedora and probably elsewhere.
  14. #
  15. # chkconfig: 2345 90 10
  16. # description: Onion Router - A low-latency anonymous proxy
  17. #
  18. PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
  19. DAEMON=/usr/sbin/tor
  20. NAME=tor
  21. DESC="tor daemon"
  22. TORPIDDIR=/var/run/tor
  23. TORPID=$TORPIDDIR/tor.pid
  24. WAITFORDAEMON=60
  25. ARGS=""
  26. # Library functions
  27. if [ -f /etc/rc.d/init.d/functions ]; then
  28. . /etc/rc.d/init.d/functions
  29. elif [ -f /etc/init.d/functions ]; then
  30. . /etc/init.d/functions
  31. fi
  32. TORCTL=@BINDIR@/torctl
  33. # torctl will use these environment variables
  34. TORUSER=@TORUSER@
  35. export TORUSER
  36. if [ -x /bin/su ] ; then
  37. SUPROG=/bin/su
  38. elif [ -x /sbin/su ] ; then
  39. SUPROG=/sbin/su
  40. elif [ -x /usr/bin/su ] ; then
  41. SUPROG=/usr/bin/su
  42. elif [ -x /usr/sbin/su ] ; then
  43. SUPROG=/usr/sbin/su
  44. else
  45. SUPROG=/bin/su
  46. fi
  47. # Raise ulimit based on number of file descriptors available (thanks, Debian)
  48. if [ -r /proc/sys/fs/file-max ]; then
  49. system_max=`cat /proc/sys/fs/file-max`
  50. if [ "$system_max" -gt "80000" ] ; then
  51. MAX_FILEDESCRIPTORS=32768
  52. elif [ "$system_max" -gt "40000" ] ; then
  53. MAX_FILEDESCRIPTORS=16384
  54. elif [ "$system_max" -gt "10000" ] ; then
  55. MAX_FILEDESCRIPTORS=8192
  56. else
  57. MAX_FILEDESCRIPTORS=1024
  58. cat << EOF
  59. Warning: Your system has very few filedescriptors available in total.
  60. Maybe you should try raising that by adding 'fs.file-max=100000' to your
  61. /etc/sysctl.conf file. Feel free to pick any number that you deem appropriate.
  62. Then run 'sysctl -p'. See /proc/sys/fs/file-max for the current value, and
  63. file-nr in the same directory for how many of those are used at the moment.
  64. EOF
  65. fi
  66. else
  67. MAX_FILEDESCRIPTORS=8192
  68. fi
  69. NICE=""
  70. case "$1" in
  71. start)
  72. if [ -n "$MAX_FILEDESCRIPTORS" ]; then
  73. echo -n "Raising maximum number of filedescriptors (ulimit -n) to $MAX_FILEDESCRIPTORS"
  74. if ulimit -n "$MAX_FILEDESCRIPTORS" ; then
  75. echo "."
  76. else
  77. echo ": FAILED."
  78. fi
  79. fi
  80. action $"Starting tor:" $TORCTL start
  81. RETVAL=$?
  82. ;;
  83. stop)
  84. action $"Stopping tor:" $TORCTL stop
  85. RETVAL=$?
  86. ;;
  87. restart)
  88. action $"Restarting tor:" $TORCTL restart
  89. RETVAL=$?
  90. ;;
  91. reload)
  92. action $"Reloading tor:" $TORCTL reload
  93. RETVAL=$?
  94. ;;
  95. status)
  96. $TORCTL status
  97. RETVAL=$?
  98. ;;
  99. *)
  100. echo "Usage: $0 (start|stop|restart|reload|status)"
  101. RETVAL=1
  102. esac
  103. exit $RETVAL