tor.init 2.1 KB

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