control event logs include loglevel notice
[tor.git] / debian / tor.init
blob640a5e88c81534e462f7bb4c26f4745e7dbdab59
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 TORLOG=/var/log/tor/log
10 TORPID=/var/run/tor/tor.pid
11 DEFAULTSFILE=/etc/default/$NAME
12 WAITFORDAEMON=10
13 ARGS="--pidfile $TORPID --logfile $TORLOG --runasdaemon 1"
15 test -x $DAEMON || exit 0
17 # Include tor defaults if available
18 if [ -f $DEFAULTSFILE ] ; then
19 . $DEFAULTSFILE
22 wait_for_deaddaemon () {
23 pid=$1
24 sleep 1
25 if test -n "$pid"
26 then
27 if kill -0 $pid 2>/dev/null
28 then
29 echo -n "."
30 cnt=0
31 while kill -0 $pid 2>/dev/null
33 cnt=`expr $cnt + 1`
34 if [ $cnt -gt $WAITFORDAEMON ]
35 then
36 echo " FAILED."
37 return 1
39 sleep 1
40 echo -n "."
41 done
44 return 0
47 case "$1" in
48 start)
49 if [ "$RUN_DAEMON" != "yes" ]; then
50 echo "Not starting $DESC (Disabled in $DEFAULTSFILE)."
51 else
52 echo -n "Starting $DESC: "
53 start-stop-daemon --start --quiet --oknodo \
54 --chuid debian-tor:debian-tor \
55 --pidfile $TORPID \
56 --exec $DAEMON -- $ARGS
57 echo "$NAME."
60 stop)
61 echo -n "Stopping $DESC: "
62 pid=`cat $TORPID 2>/dev/null` || true
63 if test ! -f $TORPID -o -z "$pid"
64 then
65 echo "not running (there is no $TORPID)."
66 elif start-stop-daemon --stop --quiet --pidfile $TORPID --exec $DAEMON
67 then
68 wait_for_deaddaemon $pid
69 echo "$NAME."
70 elif kill -0 $pid 2>/dev/null
71 then
72 echo "FAILED (Is $pid not $NAME? Is $DAEMON a different binary now?)."
73 else
74 echo "FAILED ($DAEMON died: process $pid not running; or permission denied)."
77 reload|force-reload)
78 echo -n "Reloading $DESC configuration: "
79 pid=`cat $TORPID 2>/dev/null` || true
80 if test ! -f $TORPID -o -z "$pid"
81 then
82 echo "not running (there is no $TORPID)."
83 elif start-stop-daemon --stop --signal 1 --quiet --pidfile $TORPID --exec $DAEMON
84 then
85 echo "$NAME."
86 elif kill -0 $pid 2>/dev/null
87 then
88 echo "FAILED (Is $pid not $NAME? Is $DAEMON a different binary now?)."
89 else
90 echo "FAILED ($DAEMON died: process $pid not running; or permission denied)."
93 restart)
94 $0 stop
95 sleep 1
96 $0 start
99 echo "Usage: $0 {start|stop|restart|reload|force-reload}" >&2
100 exit 1
102 esac
104 exit 0