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 Warning: Your system has very few filedescriptors available in total.
43 Maybe you should try raising that by adding 'fs.file-max=100000' to your
44 /etc/sysctl.conf file. Feel free to pick any number that you deem appropriate.
45 Then run 'sysctl -p'. See /proc/sys/fs/file-max for the current value, and
46 file-nr in the same directory for how many of those are used at the moment.
51 MAX_FILEDESCRIPTORS
=8192
56 test -x $DAEMON ||
exit 0
58 # Include tor defaults if available
59 if [ -f $DEFAULTSFILE ] ; then
63 wait_for_deaddaemon
() {
68 if kill -0 $pid 2>/dev
/null
72 while kill -0 $pid 2>/dev
/null
75 if [ $cnt -gt $WAITFORDAEMON ]
90 if test ! -d $TORPIDDIR; then
91 #echo "There is no $TORPIDDIR directory. Creating one for you."
92 mkdir
-m 02700 "$TORPIDDIR"
93 chown debian-tor
:debian-tor
"$TORPIDDIR"
96 if test ! -x $TORPIDDIR; then
97 echo "Cannot access $TORPIDDIR directory, are you root?" >&2
103 if ! $DAEMON --verify-config > /dev
/null
; then
104 echo "ABORTED: Tor configuration invalid:" >&2
105 $DAEMON --verify-config >&2
113 if [ "$RUN_DAEMON" != "yes" ]; then
114 echo "Not starting $DESC (Disabled in $DEFAULTSFILE)."
118 if [ -n "$MAX_FILEDESCRIPTORS" ]; then
119 echo -n "Raising maximum number of filedescriptors (ulimit -n) to $MAX_FILEDESCRIPTORS"
120 if ulimit -n "$MAX_FILEDESCRIPTORS" ; then
129 echo "Starting $DESC: $NAME..."
132 start-stop-daemon
--start --quiet --oknodo \
135 --exec $DAEMON -- $ARGS
139 echo -n "Stopping $DESC: "
140 pid
=`cat $TORPID 2>/dev/null` || true
142 if test ! -f $TORPID -o -z "$pid"; then
143 echo "not running (there is no $TORPID)."
147 if start-stop-daemon
--stop --signal INT
--quiet --pidfile $TORPID --exec $DAEMON; then
148 wait_for_deaddaemon
$pid
150 elif kill -0 $pid 2>/dev
/null
152 echo "FAILED (Is $pid not $NAME? Is $DAEMON a different binary now?)."
154 echo "FAILED ($DAEMON died: process $pid not running; or permission denied)."
158 echo -n "Reloading $DESC configuration: "
159 pid
=`cat $TORPID 2>/dev/null` || true
161 if test ! -f $TORPID -o -z "$pid"; then
162 echo "not running (there is no $TORPID)."
168 if start-stop-daemon
--stop --signal 1 --quiet --pidfile $TORPID --exec $DAEMON
171 elif kill -0 $pid 2>/dev
/null
173 echo "FAILED (Is $pid not $NAME? Is $DAEMON a different binary now?)."
175 echo "FAILED ($DAEMON died: process $pid not running; or permission denied)."
186 echo "Usage: $0 {start|stop|restart|reload|force-reload}" >&2