If "with-dmalloc" is in DEB_BUILD_OPTIONS we build against libdmalloc4.
[tor.git] / debian / tor.init
blob13a3bbbb7859409061e48b65152fc5f35b85952c
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=60
12 ARGS=""
13 MAX_FILEDESCRIPTORS=4096
14 NICE=""
16 test -x $DAEMON || exit 0
18 # Include tor defaults if available
19 if [ -f $DEFAULTSFILE ] ; then
20 . $DEFAULTSFILE
23 wait_for_deaddaemon () {
24 pid=$1
25 sleep 1
26 if test -n "$pid"
27 then
28 if kill -0 $pid 2>/dev/null
29 then
30 echo -n "."
31 cnt=0
32 while kill -0 $pid 2>/dev/null
34 cnt=`expr $cnt + 1`
35 if [ $cnt -gt $WAITFORDAEMON ]
36 then
37 echo " FAILED."
38 return 1
40 sleep 1
41 echo -n "."
42 done
45 return 0
48 case "$1" in
49 start)
50 if [ "$RUN_DAEMON" != "yes" ]; then
51 echo "Not starting $DESC (Disabled in $DEFAULTSFILE)."
52 else
53 echo "Starting $DESC: $NAME..."
54 ulimit -n $MAX_FILEDESCRIPTORS
55 start-stop-daemon --start --quiet --oknodo \
56 --chuid debian-tor:debian-tor \
57 --pidfile $TORPID \
58 $NICE \
59 --exec $DAEMON -- $ARGS
60 echo "done."
63 stop)
64 echo -n "Stopping $DESC: "
65 pid=`cat $TORPID 2>/dev/null` || true
66 if test ! -f $TORPID -o -z "$pid"
67 then
68 echo "not running (there is no $TORPID)."
69 elif start-stop-daemon --stop --signal INT --quiet --pidfile $TORPID --exec $DAEMON
70 then
71 wait_for_deaddaemon $pid
72 echo "$NAME."
73 elif kill -0 $pid 2>/dev/null
74 then
75 echo "FAILED (Is $pid not $NAME? Is $DAEMON a different binary now?)."
76 else
77 echo "FAILED ($DAEMON died: process $pid not running; or permission denied)."
80 reload|force-reload)
81 echo -n "Reloading $DESC configuration: "
82 pid=`cat $TORPID 2>/dev/null` || true
83 if test ! -f $TORPID -o -z "$pid"
84 then
85 echo "not running (there is no $TORPID)."
86 elif start-stop-daemon --stop --signal 1 --quiet --pidfile $TORPID --exec $DAEMON
87 then
88 echo "$NAME."
89 elif kill -0 $pid 2>/dev/null
90 then
91 echo "FAILED (Is $pid not $NAME? Is $DAEMON a different binary now?)."
92 else
93 echo "FAILED ($DAEMON died: process $pid not running; or permission denied)."
96 restart)
97 $0 stop
98 sleep 1
99 $0 start
102 echo "Usage: $0 {start|stop|restart|reload|force-reload}" >&2
103 exit 1
105 esac
107 exit 0