Checkpoint work towards making tor.spec work with current tor and conform (more or...
[tor.git] / contrib / tor.sh.in
blobdfde1f6a45b004789843593f05ba86f396e45ebb
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 # Strictly speaking, we don't need to su if we have --user and --group.
15 # "Belt and suspenders," says jbash.
16 TORARGS="--pidfile $TORPID --logfile $TORLOG --runasdaemon 1"
17 if [ "x$TORUSER" != "x" ]; then
18 TORARGS="$TORARGS --user $TORUSER"
20 if [ "x$TORGROUP" != "x" ]; then
21 TORARGS="$TORARGS --group $TORGROUP"
23 RETVAL=0
25 case "$1" in
27 start)
28 if [ -f $TORPID ]; then
29 echo "tor appears to be already running (pid file exists)"
30 echo "Maybe you should run: $0 restart ?"
31 RETVAL=1
32 else
33 echo -n "Starting tor..."
34 if [ "x$TORUSER" = "x" ]; then
35 $TORBIN -f $TORCONF $TORARGS
36 else
37 /bin/su -c "$TORBIN -f $TORCONF $TORARGS" $TORUSER
39 RETVAL=$?
40 if [ $RETVAL -eq 0 ]; then
41 echo " ok"
42 else
43 echo " ERROR!"
48 stop)
49 if [ -f $TORPID ]; then
50 echo -n "Killing tor..."
51 kill `cat $TORPID`
52 RETVAL=$?
53 if [ $RETVAL -eq 0 ]; then
54 echo " ok"
55 else
56 echo " ERROR!"
58 else
59 echo "Unable to kill tor: $TORPID does not exist"
60 RETVAL=1
64 reload)
65 if [ -f $TORPID ]; then
66 echo -n "Sending HUP to tor..."
67 kill -HUP `cat $TORPID`
68 RETVAL=$?
69 if [ $RETVAL -eq 0 ]; then
70 echo " ok"
71 else
72 echo " ERROR!"
74 else
75 echo "Unable to kill tor: $TORPID does not exist"
76 RETVAL=1
80 restart)
81 $0 stop
82 if [ -f $TORPID ]; then
83 rm -f $TORPID
85 $0 start
89 status)
90 PID=`cat $TORPID 2>/dev/null`
91 if [ "$PID" != "" ]; then
92 torstat=`ps -p $PID | grep -c "^$PID"`
93 if [ $torstat ]; then
94 echo "tor is running ($PID)"
95 else
96 echo "tor is not running (looks like it crashed, look for core? $PID)"
98 else
99 echo "tor is not running (exited gracefully)"
103 log)
104 cat $TORLOG
108 echo "Usage: $0 (start|stop|restart|status|log)"
109 exit 1
110 esac
112 exit $RETVAL