5 # Startup/shutdown script for tor. This is a wrapper around torctl;
6 # torctl does the actual work in a relatively system-independent, or at least
7 # distribution-independent, way, and this script deals with fitting the
8 # whole thing into the conventions of the particular system at hand.
9 # This particular script is written for Red Hat/Fedora Linux, and may
10 # also work on Mandrake, but not SuSE.
12 # These next couple of lines "declare" tor for the "chkconfig" program,
13 # originally from SGI, used on Red Hat/Fedora and probably elsewhere.
15 # chkconfig: 2345 90 10
16 # description: Onion Router - A low-latency anonymous proxy
19 PATH
=/usr
/local
/sbin
:/usr
/local
/bin
:/sbin
:/bin
:/usr
/sbin
:/usr
/bin
23 TORPIDDIR
=/var
/run
/tor
24 TORPID
=$TORPIDDIR/tor.pid
29 if [ -f /etc
/rc.d
/init.d
/functions
]; then
30 .
/etc
/rc.d
/init.d
/functions
31 elif [ -f /etc
/init.d
/functions
]; then
32 .
/etc
/init.d
/functions
35 TORCTL
=@BINDIR@
/torctl
37 # torctl will use these environment variables
41 if [ -x /bin
/su
] ; then
43 elif [ -x /sbin
/su
] ; then
45 elif [ -x /usr
/bin
/su
] ; then
47 elif [ -x /usr
/sbin
/su
] ; then
53 # Raise ulimit based on number of file descriptors available (thanks, Debian)
55 if [ -r /proc
/sys
/fs
/file-max
]; then
56 system_max
=`cat /proc/sys/fs/file-max`
57 if [ "$system_max" -gt "80000" ] ; then
58 MAX_FILEDESCRIPTORS
=32768
59 elif [ "$system_max" -gt "40000" ] ; then
60 MAX_FILEDESCRIPTORS
=16384
61 elif [ "$system_max" -gt "10000" ] ; then
62 MAX_FILEDESCRIPTORS
=8192
64 MAX_FILEDESCRIPTORS
=1024
67 Warning: Your system has very few filedescriptors available in total.
69 Maybe you should try raising that by adding 'fs.file-max=100000' to your
70 /etc/sysctl.conf file. Feel free to pick any number that you deem appropriate.
71 Then run 'sysctl -p'. See /proc/sys/fs/file-max for the current value, and
72 file-nr in the same directory for how many of those are used at the moment.
77 MAX_FILEDESCRIPTORS
=8192
85 if [ -n "$MAX_FILEDESCRIPTORS" ]; then
86 echo -n "Raising maximum number of filedescriptors (ulimit -n) to $MAX_FILEDESCRIPTORS"
87 if ulimit -n "$MAX_FILEDESCRIPTORS" ; then
94 action $
"Starting tor:" $TORCTL start
99 action $
"Stopping tor:" $TORCTL stop
104 action $
"Restarting tor:" $TORCTL restart
109 action $
"Reloading tor:" $TORCTL reload
119 echo "Usage: $0 (start|stop|restart|reload|status)"