tor.init 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. #! /bin/sh
  2. set -e
  3. PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
  4. DAEMON=/usr/sbin/tor
  5. NAME=tor
  6. DESC="tor daemon"
  7. TORPID=/var/run/tor/tor.pid
  8. DEFAULTSFILE=/etc/default/$NAME
  9. WAITFORDAEMON=60
  10. ARGS=""
  11. MAX_FILEDESCRIPTORS=4096
  12. NICE=""
  13. test -x $DAEMON || exit 0
  14. # Include tor defaults if available
  15. if [ -f $DEFAULTSFILE ] ; then
  16. . $DEFAULTSFILE
  17. fi
  18. wait_for_deaddaemon () {
  19. pid=$1
  20. sleep 1
  21. if test -n "$pid"
  22. then
  23. if kill -0 $pid 2>/dev/null
  24. then
  25. echo -n "."
  26. cnt=0
  27. while kill -0 $pid 2>/dev/null
  28. do
  29. cnt=`expr $cnt + 1`
  30. if [ $cnt -gt $WAITFORDAEMON ]
  31. then
  32. echo " FAILED."
  33. return 1
  34. fi
  35. sleep 1
  36. echo -n "."
  37. done
  38. fi
  39. fi
  40. return 0
  41. }
  42. case "$1" in
  43. start)
  44. if [ "$RUN_DAEMON" != "yes" ]; then
  45. echo "Not starting $DESC (Disabled in $DEFAULTSFILE)."
  46. else
  47. echo "Starting $DESC: $NAME..."
  48. ulimit -n $MAX_FILEDESCRIPTORS
  49. start-stop-daemon --start --quiet --oknodo \
  50. --chuid debian-tor:debian-tor \
  51. --pidfile $TORPID \
  52. $NICE \
  53. --exec $DAEMON -- $ARGS
  54. echo "done."
  55. fi
  56. ;;
  57. stop)
  58. echo -n "Stopping $DESC: "
  59. pid=`cat $TORPID 2>/dev/null` || true
  60. if test ! -f $TORPID -o -z "$pid"
  61. then
  62. echo "not running (there is no $TORPID)."
  63. elif start-stop-daemon --stop --signal INT --quiet --pidfile $TORPID --exec $DAEMON
  64. then
  65. wait_for_deaddaemon $pid
  66. echo "$NAME."
  67. elif kill -0 $pid 2>/dev/null
  68. then
  69. echo "FAILED (Is $pid not $NAME? Is $DAEMON a different binary now?)."
  70. else
  71. echo "FAILED ($DAEMON died: process $pid not running; or permission denied)."
  72. fi
  73. ;;
  74. reload|force-reload)
  75. echo -n "Reloading $DESC configuration: "
  76. pid=`cat $TORPID 2>/dev/null` || true
  77. if test ! -f $TORPID -o -z "$pid"
  78. then
  79. echo "not running (there is no $TORPID)."
  80. elif start-stop-daemon --stop --signal 1 --quiet --pidfile $TORPID --exec $DAEMON
  81. then
  82. echo "$NAME."
  83. elif kill -0 $pid 2>/dev/null
  84. then
  85. echo "FAILED (Is $pid not $NAME? Is $DAEMON a different binary now?)."
  86. else
  87. echo "FAILED ($DAEMON died: process $pid not running; or permission denied)."
  88. fi
  89. ;;
  90. restart)
  91. $0 stop
  92. sleep 1
  93. $0 start
  94. ;;
  95. *)
  96. echo "Usage: $0 {start|stop|restart|reload|force-reload}" >&2
  97. exit 1
  98. ;;
  99. esac
  100. exit 0