a todo clump for tor mirror todos
[tor.git] / debian / tor.init
blobec5707d7d1afc0e100b449b7e2e11834e13a18f0
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 check_torpiddir () {
65 if test ! -d $TORPIDDIR; then
66 echo "There is no $TORPIDDIR directory. Creating one for you."
67 mkdir -m 02700 "$TORPIDDIR"
68 chown debian-tor:debian-tor "$TORPIDDIR"
71 if test ! -x $TORPIDDIR; then
72 echo "Cannot access $TORPIDDIR directory, are you root?" >&2
73 exit 1
78 case "$1" in
79 start)
80 if [ "$RUN_DAEMON" != "yes" ]; then
81 echo "Not starting $DESC (Disabled in $DEFAULTSFILE)."
82 exit 0
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 check_torpiddir
96 echo "Starting $DESC: $NAME..."
97 if ! su -s /bin/sh -c "$DAEMON --verify-config" debian-tor > /dev/null; then
98 echo "ABORTED: Tor configuration invalid:" >&2
99 su -s /bin/sh -c "$DAEMON --verify-config" debian-tor >&2
100 exit 1
103 start-stop-daemon --start --quiet --oknodo \
104 --chuid debian-tor:debian-tor \
105 --pidfile $TORPID \
106 $NICE \
107 --exec $DAEMON -- $ARGS
108 echo "done."
110 stop)
111 echo -n "Stopping $DESC: "
112 pid=`cat $TORPID 2>/dev/null` || true
114 if test ! -f $TORPID -o -z "$pid"; then
115 echo "not running (there is no $TORPID)."
116 exit 0
119 if start-stop-daemon --stop --signal INT --quiet --pidfile $TORPID --exec $DAEMON; then
120 wait_for_deaddaemon $pid
121 echo "$NAME."
122 elif kill -0 $pid 2>/dev/null
123 then
124 echo "FAILED (Is $pid not $NAME? Is $DAEMON a different binary now?)."
125 else
126 echo "FAILED ($DAEMON died: process $pid not running; or permission denied)."
129 reload|force-reload)
130 echo -n "Reloading $DESC configuration: "
131 pid=`cat $TORPID 2>/dev/null` || true
133 if test ! -f $TORPID -o -z "$pid"; then
134 echo "not running (there is no $TORPID)."
135 exit 0
138 if ! su -s /bin/sh -c "$DAEMON --verify-config" debian-tor > /dev/null; then
139 echo "ABORTED: Tor configuration invalid:" >&2
140 su -s /bin/sh -c "$DAEMON --verify-config" debian-tor >&2
141 exit 1
144 if start-stop-daemon --stop --signal 1 --quiet --pidfile $TORPID --exec $DAEMON
145 then
146 echo "$NAME."
147 elif kill -0 $pid 2>/dev/null
148 then
149 echo "FAILED (Is $pid not $NAME? Is $DAEMON a different binary now?)."
150 else
151 echo "FAILED ($DAEMON died: process $pid not running; or permission denied)."
154 restart)
155 if ! su -s /bin/sh -c "$DAEMON --verify-config" debian-tor > /dev/null; then
156 echo "Restarting Tor ABORTED: Tor configuration invalid:" >&2
157 su -s /bin/sh -c "$DAEMON --verify-config" debian-tor >&2
158 exit 1
161 $0 stop
162 sleep 1
163 $0 start
166 echo "Usage: $0 {start|stop|restart|reload|force-reload}" >&2
167 exit 1
169 esac
171 exit 0