Merge remote branch 'sebastian/remove-osx-expert-package' into maint-0.2.2
[tor/rransom.git] / contrib / tor.sh.in
blob92f890681fa28ec696c0d2bcd30f6448be2eb1d2
1 #!/bin/sh
3 # tor The Onion Router
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
20 DAEMON=/usr/sbin/tor
21 NAME=tor
22 DESC="tor daemon"
23 TORPIDDIR=/var/run/tor
24 TORPID=$TORPIDDIR/tor.pid
25 WAITFORDAEMON=60
26 ARGS=""
28 # Library functions
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
38 TORUSER=@TORUSER@
39 export TORUSER
41 if [ -x /bin/su ] ; then
42 SUPROG=/bin/su
43 elif [ -x /sbin/su ] ; then
44 SUPROG=/sbin/su
45 elif [ -x /usr/bin/su ] ; then
46 SUPROG=/usr/bin/su
47 elif [ -x /usr/sbin/su ] ; then
48 SUPROG=/usr/sbin/su
49 else
50 SUPROG=/bin/su
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
63 else
64 MAX_FILEDESCRIPTORS=1024
65 cat << EOF
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.
74 EOF
76 else
77 MAX_FILEDESCRIPTORS=8192
80 NICE=""
82 case "$1" in
84 start)
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
88 echo "."
89 else
90 echo ": FAILED."
94 action $"Starting tor:" $TORCTL start
95 RETVAL=$?
98 stop)
99 action $"Stopping tor:" $TORCTL stop
100 RETVAL=$?
103 restart)
104 action $"Restarting tor:" $TORCTL restart
105 RETVAL=$?
108 reload)
109 action $"Reloading tor:" $TORCTL reload
110 RETVAL=$?
113 status)
114 $TORCTL status
115 RETVAL=$?
119 echo "Usage: $0 (start|stop|restart|reload|status)"
120 RETVAL=1
121 esac
123 exit $RETVAL