tor.sh.in 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. #!/bin/sh
  2. #
  3. # Copyright (c) 2006-2007 Andrew Lewman
  4. #
  5. # tor The Onion Router
  6. #
  7. # Startup/shutdown script for tor. This is a wrapper around torctl;
  8. # torctl does the actual work in a relatively system-independent, or at least
  9. # distribution-independent, way, and this script deals with fitting the
  10. # whole thing into the conventions of the particular system at hand.
  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. ### BEGIN INIT INFO
  19. # Provides: tor
  20. # Required-Start: $remote_fs $network
  21. # Required-Stop: $remote_fs $network
  22. # Default-Start: 3 5
  23. # Default-Stop: 0 1 2 6
  24. # Short-Description: Start the tor daemon
  25. # Description: Start the tor daemon: the anon-proxy server
  26. ### END INIT INFO
  27. . /etc/rc.status
  28. # Shell functions sourced from /etc/rc.status:
  29. # rc_check check and set local and overall rc status
  30. # rc_status check and set local and overall rc status
  31. # rc_status -v ditto but be verbose in local rc status
  32. # rc_status -v -r ditto and clear the local rc status
  33. # rc_failed set local and overall rc status to failed
  34. # rc_reset clear local rc status (overall remains)
  35. # rc_exit exit appropriate to overall rc status
  36. # First reset status of this service
  37. rc_reset
  38. # Increase open file descriptors a reasonable amount
  39. ulimit -n 8192
  40. TORCTL=@BINDIR@/torctl
  41. # torctl will use these environment variables
  42. TORUSER=@TORUSER@
  43. export TORUSER
  44. TORGROUP=@TORGROUP@
  45. export TORGROUP
  46. TOR_DAEMON_PID_DIR="@LOCALSTATEDIR@/run/tor"
  47. if [ -x /bin/su ] ; then
  48. SUPROG=/bin/su
  49. elif [ -x /sbin/su ] ; then
  50. SUPROG=/sbin/su
  51. elif [ -x /usr/bin/su ] ; then
  52. SUPROG=/usr/bin/su
  53. elif [ -x /usr/sbin/su ] ; then
  54. SUPROG=/usr/sbin/su
  55. else
  56. SUPROG=/bin/su
  57. fi
  58. case "$1" in
  59. start)
  60. echo "Starting tor daemon"
  61. if [ ! -d $TOR_DAEMON_PID_DIR ] ; then
  62. mkdir -p $TOR_DAEMON_PID_DIR
  63. chown $TORUSER:$TORGROUP $TOR_DAEMON_PID_DIR
  64. fi
  65. ## Start daemon with startproc(8). If this fails
  66. ## the echo return value is set appropriate.
  67. startproc -f $TORCTL start
  68. # Remember status and be verbose
  69. rc_status -v
  70. ;;
  71. stop)
  72. echo "Stopping tor daemon"
  73. startproc -f $TORCTL stop
  74. # Remember status and be verbose
  75. rc_status -v
  76. ;;
  77. restart)
  78. echo "Restarting tor daemon"
  79. startproc -f $TORCTL restart
  80. # Remember status and be verbose
  81. rc_status -v
  82. ;;
  83. reload)
  84. echo "Reloading tor daemon"
  85. startproc -f $TORCTL reload
  86. # Remember status and be verbose
  87. rc_status -v
  88. ;;
  89. status)
  90. startproc -f $TORCTL status
  91. # Remember status and be verbose
  92. rc_status -v
  93. ;;
  94. *)
  95. echo "Usage: $0 (start|stop|restart|reload|status)"
  96. RETVAL=1
  97. esac
  98. rc_exit