Make filename lines in proposals match actual filenames. Accept 135.
[tor.git] / debian / tor.init
blobea71e94bb221a3b04b32be43e59aee90b87e82d9
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
40 else
41 MAX_FILEDESCRIPTORS=8192
44 NICE=""
46 test -x $DAEMON || exit 0
48 # Include tor defaults if available
49 if [ -f $DEFAULTSFILE ] ; then
50 . $DEFAULTSFILE
53 wait_for_deaddaemon () {
54 pid=$1
55 sleep 1
56 if test -n "$pid"
57 then
58 if kill -0 $pid 2>/dev/null
59 then
60 echo -n "."
61 cnt=0
62 while kill -0 $pid 2>/dev/null
64 cnt=`expr $cnt + 1`
65 if [ $cnt -gt $WAITFORDAEMON ]
66 then
67 echo " FAILED."
68 return 1
70 sleep 1
71 echo -n "."
72 done
75 return 0
79 check_torpiddir () {
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
88 exit 1
92 check_config () {
93 if ! $DAEMON --verify-config > /dev/null; then
94 echo "ABORTED: Tor configuration invalid:" >&2
95 $DAEMON --verify-config >&2
96 exit 1
101 case "$1" in
102 start)
103 if [ "$RUN_DAEMON" != "yes" ]; then
104 echo "Not starting $DESC (Disabled in $DEFAULTSFILE)."
105 exit 0
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
111 echo "."
112 else
113 echo ": FAILED."
117 check_torpiddir
119 echo "Starting $DESC: $NAME..."
120 check_config
122 start-stop-daemon --start --quiet --oknodo \
123 --pidfile $TORPID \
124 $NICE \
125 --exec $DAEMON -- $ARGS
126 echo "done."
128 stop)
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)."
134 exit 0
137 if start-stop-daemon --stop --signal INT --quiet --pidfile $TORPID --exec $DAEMON; then
138 wait_for_deaddaemon $pid
139 echo "$NAME."
140 elif kill -0 $pid 2>/dev/null
141 then
142 echo "FAILED (Is $pid not $NAME? Is $DAEMON a different binary now?)."
143 else
144 echo "FAILED ($DAEMON died: process $pid not running; or permission denied)."
147 reload|force-reload)
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)."
153 exit 0
156 check_config
158 if start-stop-daemon --stop --signal 1 --quiet --pidfile $TORPID --exec $DAEMON
159 then
160 echo "$NAME."
161 elif kill -0 $pid 2>/dev/null
162 then
163 echo "FAILED (Is $pid not $NAME? Is $DAEMON a different binary now?)."
164 else
165 echo "FAILED ($DAEMON died: process $pid not running; or permission denied)."
168 restart)
169 check_config
171 $0 stop
172 sleep 1
173 $0 start
176 echo "Usage: $0 {start|stop|restart|reload|force-reload}" >&2
177 exit 1
179 esac
181 exit 0