a dir-spec typo (in two places) caught by steve
[tor.git] / debian / tor.init
blobe4a9310666738f6c0ff807b7eabf11392b13e7d8
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 MAX_FILEDESCRIPTORS=8192
29 NICE=""
31 test -x $DAEMON || exit 0
33 # Include tor defaults if available
34 if [ -f $DEFAULTSFILE ] ; then
35 . $DEFAULTSFILE
38 wait_for_deaddaemon () {
39 pid=$1
40 sleep 1
41 if test -n "$pid"
42 then
43 if kill -0 $pid 2>/dev/null
44 then
45 echo -n "."
46 cnt=0
47 while kill -0 $pid 2>/dev/null
49 cnt=`expr $cnt + 1`
50 if [ $cnt -gt $WAITFORDAEMON ]
51 then
52 echo " FAILED."
53 return 1
55 sleep 1
56 echo -n "."
57 done
60 return 0
64 if test ! -d $TORPIDDIR; then
65 echo "There is no $TORPIDDIR directory. Creating one for you."
66 mkdir -m 02700 "$TORPIDDIR"
67 chown debian-tor:debian-tor "$TORPIDDIR"
70 if test ! -x $TORPIDDIR; then
71 echo "Cannot access $TORPIDDIR directory, are you root?" >&2
72 exit 1
76 case "$1" in
77 start)
78 if [ "$RUN_DAEMON" != "yes" ]; then
79 echo "Not starting $DESC (Disabled in $DEFAULTSFILE)."
80 exit 0
83 if [ -n "$MAX_FILEDESCRIPTORS" ]; then
84 echo -n "Raising maximum number of filedescriptors (ulimit -n) to $MAX_FILEDESCRIPTORS"
85 if ulimit -n "$MAX_FILEDESCRIPTORS" ; then
86 echo "."
87 else
88 echo ": FAILED."
92 echo "Starting $DESC: $NAME..."
93 if ! su -s /bin/sh -c "$DAEMON --verify-config" debian-tor > /dev/null; then
94 echo "ABORTED: Tor configuration invalid:" >&2
95 su -s /bin/sh -c "$DAEMON --verify-config" debian-tor >&2
96 exit 1
99 start-stop-daemon --start --quiet --oknodo \
100 --chuid debian-tor:debian-tor \
101 --pidfile $TORPID \
102 $NICE \
103 --exec $DAEMON -- $ARGS
104 echo "done."
106 stop)
107 echo -n "Stopping $DESC: "
108 pid=`cat $TORPID 2>/dev/null` || true
110 if test ! -f $TORPID -o -z "$pid"; then
111 echo "not running (there is no $TORPID)."
112 exit 0
115 if start-stop-daemon --stop --signal INT --quiet --pidfile $TORPID --exec $DAEMON; then
116 wait_for_deaddaemon $pid
117 echo "$NAME."
118 elif kill -0 $pid 2>/dev/null
119 then
120 echo "FAILED (Is $pid not $NAME? Is $DAEMON a different binary now?)."
121 else
122 echo "FAILED ($DAEMON died: process $pid not running; or permission denied)."
125 reload|force-reload)
126 echo -n "Reloading $DESC configuration: "
127 pid=`cat $TORPID 2>/dev/null` || true
129 if test ! -f $TORPID -o -z "$pid"; then
130 echo "not running (there is no $TORPID)."
131 exit 0
134 if ! su -s /bin/sh -c "$DAEMON --verify-config" debian-tor > /dev/null; then
135 echo "ABORTED: Tor configuration invalid:" >&2
136 su -s /bin/sh -c "$DAEMON --verify-config" debian-tor >&2
137 exit 1
140 if start-stop-daemon --stop --signal 1 --quiet --pidfile $TORPID --exec $DAEMON
141 then
142 echo "$NAME."
143 elif kill -0 $pid 2>/dev/null
144 then
145 echo "FAILED (Is $pid not $NAME? Is $DAEMON a different binary now?)."
146 else
147 echo "FAILED ($DAEMON died: process $pid not running; or permission denied)."
150 restart)
151 if ! su -s /bin/sh -c "$DAEMON --verify-config" debian-tor > /dev/null; then
152 echo "Restarting Tor ABORTED: Tor configuration invalid:" >&2
153 su -s /bin/sh -c "$DAEMON --verify-config" debian-tor >&2
154 exit 1
157 $0 stop
158 sleep 1
159 $0 start
162 echo "Usage: $0 {start|stop|restart|reload|force-reload}" >&2
163 exit 1
165 esac
167 exit 0