Funny. I could have sworn that it compiled.
[tor.git] / debian / tor.init
blobe0e4709f25a3a7b5bab095aef7d2dc10e700c4ca
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=4096
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
63 case "$1" in
64 start)
65 if [ "$RUN_DAEMON" != "yes" ]; then
66 echo "Not starting $DESC (Disabled in $DEFAULTSFILE)."
67 else
68 if test ! -d $TORPIDDIR; then echo "There is no $TORPIDDIR directory." >&2; exit 1
69 elif test ! -x $TORPIDDIR; then echo "Cannot access $TORPIDDIR directory, are you root?" >&2; exit 1;
70 else
71 echo "Starting $DESC: $NAME..."
72 ulimit -n $MAX_FILEDESCRIPTORS || echo "Warn: Could not set ulimit for number of file descriptors." >&2
73 start-stop-daemon --start --quiet --oknodo \
74 --chuid debian-tor:debian-tor \
75 --pidfile $TORPID \
76 $NICE \
77 --exec $DAEMON -- $ARGS
78 echo "done."
82 stop)
83 echo -n "Stopping $DESC: "
84 pid=`cat $TORPID 2>/dev/null` || true
85 if test ! -d $TORPIDDIR; then echo "There is no $TORPIDDIR directory." >&2; exit 1
86 elif test ! -x $TORPIDDIR; then echo "Cannot access $TORPIDDIR directory, are you root?" >&2; exit 1;
87 elif test ! -f $TORPID -o -z "$pid"
88 then
89 echo "not running (there is no $TORPID)."
90 elif start-stop-daemon --stop --signal INT --quiet --pidfile $TORPID --exec $DAEMON
91 then
92 wait_for_deaddaemon $pid
93 echo "$NAME."
94 elif kill -0 $pid 2>/dev/null
95 then
96 echo "FAILED (Is $pid not $NAME? Is $DAEMON a different binary now?)."
97 else
98 echo "FAILED ($DAEMON died: process $pid not running; or permission denied)."
101 reload|force-reload)
102 echo -n "Reloading $DESC configuration: "
103 pid=`cat $TORPID 2>/dev/null` || true
104 if test ! -d $TORPIDDIR; then echo "There is no $TORPIDDIR directory." >&2; exit 1
105 elif test ! -x $TORPIDDIR; then echo "Cannot access $TORPIDDIR directory, are you root?" >&2; exit 1;
106 elif test ! -f $TORPID -o -z "$pid"
107 then
108 echo "not running (there is no $TORPID)."
109 elif start-stop-daemon --stop --signal 1 --quiet --pidfile $TORPID --exec $DAEMON
110 then
111 echo "$NAME."
112 elif kill -0 $pid 2>/dev/null
113 then
114 echo "FAILED (Is $pid not $NAME? Is $DAEMON a different binary now?)."
115 else
116 echo "FAILED ($DAEMON died: process $pid not running; or permission denied)."
119 restart)
120 $0 stop
121 sleep 1
122 $0 start
125 echo "Usage: $0 {start|stop|restart|reload|force-reload}" >&2
126 exit 1
128 esac
130 exit 0