Third time--is it right now?
[tor.git] / tor.sh.in
blobecf3cb32d82752fe834c1bd94f380e3985d056f8
1 #!/bin/sh
3 TORBIN=@BINDIR@/tor
4 TORPID=@LOCALSTATEDIR@/run/tor.pid
5 TORLOG=@LOCALSTATEDIR@/log/tor/tor.log
6 TORCONF=@CONFDIR@/torrc
7 TORARGS="--pidfile $TORPID --logfile $TORLOG --runasdaemon 1"
8 RETVAL=0
10 case "$1" in
12 start)
13 if [ -f $TORPID ]; then
14 echo "tor appears to be already running (pid file exists)"
15 echo "Maybe you should run: $0 restart ?"
16 RETVAL=1
17 else
18 echo -n "Starting tor..."
19 $TORBIN -f $TORCONF $TORARGS
20 RETVAL=$?
21 if [ $RETVAL -eq 0 ]; then
22 echo " ok"
23 else
24 echo " ERROR!"
29 stop)
30 if [ -f $TORPID ]; then
31 echo -n "Killing tor..."
32 kill `cat $TORPID`
33 RETVAL=$?
34 if [ $RETVAL -eq 0 ]; then
35 echo " ok"
36 else
37 echo " ERROR!"
39 else
40 echo "Unable to kill tor: $TORPID does not exist"
41 RETVAL=1
45 restart)
46 $0 stop
47 if [ -f $TORPID ]; then
48 rm -f $TORPID
50 $0 start
53 status)
54 PID=`cat $TORPID 2>/dev/null`
55 if [ "$PID" != "" ]; then
56 torstat=`ps -p $PID | grep -c "^$PID"`
57 if [ $torstat ]; then
58 echo "tor is running ($PID)"
59 else
60 echo "tor is not running (looks like it crashed, look for core? $PID)"
62 else
63 echo "tor is not running (exited gracefully)"
67 log)
68 cat $TORLOG
72 echo "Usage: $0 (start|stop|restart|status|log)"
73 exit 1
74 esac
76 exit $RETVAL