Use nick's patch against config. in the rc1 debian package
[tor.git] / debian / tor.init
blob3763996f9f30e661ddec9aa7d5bb708ee36a58a5
1 #! /bin/sh
3 set -e
5 PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
6 DAEMON=/usr/sbin/tor
7 NAME=tor
8 DESC="tor daemon"
9 TORPID=/var/run/tor/tor.pid
10 DEFAULTSFILE=/etc/default/$NAME
11 WAITFORDAEMON=10
12 ARGS=""
14 test -x $DAEMON || exit 0
16 # Include tor defaults if available
17 if [ -f $DEFAULTSFILE ] ; then
18 . $DEFAULTSFILE
21 wait_for_deaddaemon () {
22 pid=$1
23 sleep 1
24 if test -n "$pid"
25 then
26 if kill -0 $pid 2>/dev/null
27 then
28 echo -n "."
29 cnt=0
30 while kill -0 $pid 2>/dev/null
32 cnt=`expr $cnt + 1`
33 if [ $cnt -gt $WAITFORDAEMON ]
34 then
35 echo " FAILED."
36 return 1
38 sleep 1
39 echo -n "."
40 done
43 return 0
46 case "$1" in
47 start)
48 if [ "$RUN_DAEMON" != "yes" ]; then
49 echo "Not starting $DESC (Disabled in $DEFAULTSFILE)."
50 else
51 echo "Starting $DESC: $NAME..."
52 start-stop-daemon --start --quiet --oknodo \
53 --chuid debian-tor:debian-tor \
54 --pidfile $TORPID \
55 --exec $DAEMON -- $ARGS
56 echo "done."
59 stop)
60 echo -n "Stopping $DESC: "
61 pid=`cat $TORPID 2>/dev/null` || true
62 if test ! -f $TORPID -o -z "$pid"
63 then
64 echo "not running (there is no $TORPID)."
65 elif start-stop-daemon --stop --quiet --pidfile $TORPID --exec $DAEMON
66 then
67 wait_for_deaddaemon $pid
68 echo "$NAME."
69 elif kill -0 $pid 2>/dev/null
70 then
71 echo "FAILED (Is $pid not $NAME? Is $DAEMON a different binary now?)."
72 else
73 echo "FAILED ($DAEMON died: process $pid not running; or permission denied)."
76 reload|force-reload)
77 echo -n "Reloading $DESC configuration: "
78 pid=`cat $TORPID 2>/dev/null` || true
79 if test ! -f $TORPID -o -z "$pid"
80 then
81 echo "not running (there is no $TORPID)."
82 elif start-stop-daemon --stop --signal 1 --quiet --pidfile $TORPID --exec $DAEMON
83 then
84 echo "$NAME."
85 elif kill -0 $pid 2>/dev/null
86 then
87 echo "FAILED (Is $pid not $NAME? Is $DAEMON a different binary now?)."
88 else
89 echo "FAILED ($DAEMON died: process $pid not running; or permission denied)."
92 restart)
93 $0 stop
94 sleep 1
95 $0 start
98 echo "Usage: $0 {start|stop|restart|reload|force-reload}" >&2
99 exit 1
101 esac
103 exit 0