Make init script work with chkconfig; make it put pids in /var/run/tor (not /var...
[tor.git] / contrib / tor.sh.in
bloba3ffaaa39d06d7b1f7997dcef53702cbc54bf8fa
1 #!/bin/sh
3 #tor The Onion Router
5 #chkconfig:2345 90 10
6 #description: Onion Router
8 TORUSER=
9 TORGROUP=
10 TORBIN=@BINDIR@/tor
11 TORPID=@LOCALSTATEDIR@/run/tor/tor.pid
12 TORLOG=@LOCALSTATEDIR@/log/tor/tor.log
13 TORCONF=@CONFDIR@/torrc
14 if [ "x$TORUSER" -eq "x" ]; then
15 TORARGS="--pidfile $TORPID --logfile $TORLOG --runasdaemon 1"
16 else
17 TORARGS="--pidfile $TORPID --logfile $TORLOG --runasdaemon 1 --user $TORUSER --group $TORGROUP"
19 RETVAL=0
21 case "$1" in
23 start)
24 if [ -f $TORPID ]; then
25 echo "tor appears to be already running (pid file exists)"
26 echo "Maybe you should run: $0 restart ?"
27 RETVAL=1
28 else
29 echo -n "Starting tor..."
30 if [ "x$TORUSER" -eq "x" ]; then
31 $TORBIN -f $TORCONF $TORARGS
32 else
33 /bin/su -c "$TORBIN -f $TORCONF $TORARGS" $TORUSER
35 RETVAL=$?
36 if [ $RETVAL -eq 0 ]; then
37 echo " ok"
38 else
39 echo " ERROR!"
44 stop)
45 if [ -f $TORPID ]; then
46 echo -n "Killing tor..."
47 kill `cat $TORPID`
48 RETVAL=$?
49 if [ $RETVAL -eq 0 ]; then
50 echo " ok"
51 else
52 echo " ERROR!"
54 else
55 echo "Unable to kill tor: $TORPID does not exist"
56 RETVAL=1
60 restart)
61 $0 stop
62 if [ -f $TORPID ]; then
63 rm -f $TORPID
65 $0 start
68 status)
69 PID=`cat $TORPID 2>/dev/null`
70 if [ "$PID" != "" ]; then
71 torstat=`ps -p $PID | grep -c "^$PID"`
72 if [ $torstat ]; then
73 echo "tor is running ($PID)"
74 else
75 echo "tor is not running (looks like it crashed, look for core? $PID)"
77 else
78 echo "tor is not running (exited gracefully)"
82 log)
83 cat $TORLOG
87 echo "Usage: $0 (start|stop|restart|status|log)"
88 exit 1
89 esac
91 exit $RETVAL