5 # Required-Start: $local_fs $remote_fs $network $named $time
6 # Required-Stop: $local_fs $remote_fs $network $named $time
7 # Should-Start: $syslog
9 # Default-Start: 2 3 4 5
11 # Short-Description: Starts The Onion Router daemon processes
12 # Description: Start The Onion Router, a TCP overlay
13 # network client that provides anonymous
19 PATH
=/usr
/local
/sbin
:/usr
/local
/bin
:/sbin
:/bin
:/usr
/sbin
:/usr
/bin
23 TORPIDDIR
=/var
/run
/tor
24 TORPID
=$TORPIDDIR/tor.pid
25 DEFAULTSFILE
=/etc
/default
/$NAME
28 # Let's try to figure our some sane defaults:
29 if [ -r /proc
/sys
/fs
/file-max
]; then
30 system_max
=`cat /proc/sys/fs/file-max`
31 if [ "$system_max" -gt "80000" ] ; then
32 MAX_FILEDESCRIPTORS
=32768
33 elif [ "$system_max" -gt "40000" ] ; then
34 MAX_FILEDESCRIPTORS
=16384
35 elif [ "$system_max" -gt "10000" ] ; then
36 MAX_FILEDESCRIPTORS
=8192
38 MAX_FILEDESCRIPTORS
=1024
41 MAX_FILEDESCRIPTORS
=8192
46 test -x $DAEMON ||
exit 0
48 # Include tor defaults if available
49 if [ -f $DEFAULTSFILE ] ; then
53 wait_for_deaddaemon
() {
58 if kill -0 $pid 2>/dev
/null
62 while kill -0 $pid 2>/dev
/null
65 if [ $cnt -gt $WAITFORDAEMON ]
80 if test ! -d $TORPIDDIR; then
81 echo "There is no $TORPIDDIR directory. Creating one for you."
82 mkdir
-m 02700 "$TORPIDDIR"
83 chown debian-tor
:debian-tor
"$TORPIDDIR"
86 if test ! -x $TORPIDDIR; then
87 echo "Cannot access $TORPIDDIR directory, are you root?" >&2
93 if ! $DAEMON --verify-config > /dev
/null
; then
94 echo "ABORTED: Tor configuration invalid:" >&2
95 $DAEMON --verify-config >&2
103 if [ "$RUN_DAEMON" != "yes" ]; then
104 echo "Not starting $DESC (Disabled in $DEFAULTSFILE)."
108 if [ -n "$MAX_FILEDESCRIPTORS" ]; then
109 echo -n "Raising maximum number of filedescriptors (ulimit -n) to $MAX_FILEDESCRIPTORS"
110 if ulimit -n "$MAX_FILEDESCRIPTORS" ; then
119 echo "Starting $DESC: $NAME..."
122 start-stop-daemon
--start --quiet --oknodo \
125 --exec $DAEMON -- $ARGS
129 echo -n "Stopping $DESC: "
130 pid
=`cat $TORPID 2>/dev/null` || true
132 if test ! -f $TORPID -o -z "$pid"; then
133 echo "not running (there is no $TORPID)."
137 if start-stop-daemon
--stop --signal INT
--quiet --pidfile $TORPID --exec $DAEMON; then
138 wait_for_deaddaemon
$pid
140 elif kill -0 $pid 2>/dev
/null
142 echo "FAILED (Is $pid not $NAME? Is $DAEMON a different binary now?)."
144 echo "FAILED ($DAEMON died: process $pid not running; or permission denied)."
148 echo -n "Reloading $DESC configuration: "
149 pid
=`cat $TORPID 2>/dev/null` || true
151 if test ! -f $TORPID -o -z "$pid"; then
152 echo "not running (there is no $TORPID)."
158 if start-stop-daemon
--stop --signal 1 --quiet --pidfile $TORPID --exec $DAEMON
161 elif kill -0 $pid 2>/dev
/null
163 echo "FAILED (Is $pid not $NAME? Is $DAEMON a different binary now?)."
165 echo "FAILED ($DAEMON died: process $pid not running; or permission denied)."
176 echo "Usage: $0 {start|stop|restart|reload|force-reload}" >&2