Use a consistent naming standard for header file guard macros, taking care not to...
[tor/rransom.git] / debian / tor.init
bloba798c0cdf2d70079fcab4e9e33e71166c85d63b5
1 #! /bin/bash
3 ### BEGIN INIT INFO
4 # Provides: tor
5 # Required-Start: $local_fs $remote_fs $network $named $time
6 # Required-Stop: $local_fs $remote_fs $network $named $time
7 # Should-Start: $syslog
8 # Should-Stop: $syslog
9 # Default-Start: 2 3 4 5
10 # Default-Stop: 0 1 6
11 # Short-Description: Starts The Onion Router daemon processes
12 # Description: Start The Onion Router, a TCP overlay
13 # network client that provides anonymous
14 # transport.
15 ### END INIT INFO
17 set -e
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 DEFAULTSFILE=/etc/default/$NAME
26 WAITFORDAEMON=60
27 ARGS=""
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
37 else
38 MAX_FILEDESCRIPTORS=1024
39 cat << EOF
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.
48 EOF
50 else
51 MAX_FILEDESCRIPTORS=8192
54 NICE=""
56 test -x $DAEMON || exit 0
58 # Include tor defaults if available
59 if [ -f $DEFAULTSFILE ] ; then
60 . $DEFAULTSFILE
63 wait_for_deaddaemon () {
64 pid=$1
65 sleep 1
66 if test -n "$pid"
67 then
68 if kill -0 $pid 2>/dev/null
69 then
70 echo -n "."
71 cnt=0
72 while kill -0 $pid 2>/dev/null
74 cnt=`expr $cnt + 1`
75 if [ $cnt -gt $WAITFORDAEMON ]
76 then
77 echo " FAILED."
78 return 1
80 sleep 1
81 echo -n "."
82 done
85 return 0
89 check_torpiddir () {
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
98 exit 1
102 check_config () {
103 if ! $DAEMON --verify-config > /dev/null; then
104 echo "ABORTED: Tor configuration invalid:" >&2
105 $DAEMON --verify-config >&2
106 exit 1
111 case "$1" in
112 start)
113 if [ "$RUN_DAEMON" != "yes" ]; then
114 echo "Not starting $DESC (Disabled in $DEFAULTSFILE)."
115 exit 0
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
121 echo "."
122 else
123 echo ": FAILED."
127 check_torpiddir
129 echo "Starting $DESC: $NAME..."
130 check_config
132 start-stop-daemon --start --quiet --oknodo \
133 --pidfile $TORPID \
134 $NICE \
135 --exec $DAEMON -- $ARGS
136 echo "done."
138 stop)
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)."
144 exit 0
147 if start-stop-daemon --stop --signal INT --quiet --pidfile $TORPID --exec $DAEMON; then
148 wait_for_deaddaemon $pid
149 echo "$NAME."
150 elif kill -0 $pid 2>/dev/null
151 then
152 echo "FAILED (Is $pid not $NAME? Is $DAEMON a different binary now?)."
153 else
154 echo "FAILED ($DAEMON died: process $pid not running; or permission denied)."
157 reload|force-reload)
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)."
163 exit 0
166 check_config
168 if start-stop-daemon --stop --signal 1 --quiet --pidfile $TORPID --exec $DAEMON
169 then
170 echo "$NAME."
171 elif kill -0 $pid 2>/dev/null
172 then
173 echo "FAILED (Is $pid not $NAME? Is $DAEMON a different binary now?)."
174 else
175 echo "FAILED ($DAEMON died: process $pid not running; or permission denied)."
178 restart)
179 check_config
181 $0 stop
182 sleep 1
183 $0 start
186 echo "Usage: $0 {start|stop|restart|reload|force-reload}" >&2
187 exit 1
189 esac
191 exit 0