tor.init 2.1 KB

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