fix more grammar stuff
[tor.git] / contrib / tor.sh.in
blobb0a76314ddc48232a281657667e8786f0634116b
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 TORDATA=@LOCALSTATEDIR@/lib/tor
15 TORCONF=@CONFDIR@/torrc
16 # Strictly speaking, we don't need to su if we have --user and --group.
17 # "Belt and suspenders," says jbash.
18 TORARGS="--pidfile $TORPID --log \"notice file $TORLOG \" --runasdaemon 1 --datadirectory $TORDATA"
19 if [ "x$TORUSER" != "x" ]; then
20 TORARGS="$TORARGS --user $TORUSER"
22 if [ "x$TORGROUP" != "x" ]; then
23 TORARGS="$TORARGS --group $TORGROUP"
25 RETVAL=0
27 case "$1" in
29 start)
30 if [ -f $TORPID ]; then
31 echo "tor appears to be already running (pid file exists)"
32 echo "Maybe you should run: $0 restart ?"
33 RETVAL=1
34 else
35 echo -n "Starting tor..."
36 if [ "x$TORUSER" = "x" ]; then
37 $TORBIN -f $TORCONF $TORARGS
38 else
39 /bin/su -c "$TORBIN -f $TORCONF $TORARGS" $TORUSER
41 RETVAL=$?
42 if [ $RETVAL -eq 0 ]; then
43 echo " ok"
44 else
45 echo " ERROR!"
50 stop)
51 if [ -f $TORPID ]; then
52 echo -n "Killing tor..."
53 kill `cat $TORPID`
54 RETVAL=$?
55 if [ $RETVAL -eq 0 ]; then
56 echo " ok"
57 else
58 echo " ERROR!"
60 else
61 echo "Unable to kill tor: $TORPID does not exist. Assuming already dead."
62 RETVAL=0
66 reload)
67 if [ -f $TORPID ]; then
68 echo -n "Sending HUP to tor..."
69 kill -HUP `cat $TORPID`
70 RETVAL=$?
71 if [ $RETVAL -eq 0 ]; then
72 echo " ok"
73 else
74 echo " ERROR!"
76 else
77 echo "Unable to kill tor: $TORPID does not exist"
78 RETVAL=1
82 restart)
83 $0 stop
84 if [ -f $TORPID ]; then
85 rm -f $TORPID
87 $0 start
90 status)
91 PID=`cat $TORPID 2>/dev/null`
92 if [ "$PID" != "" ]; then
93 torstat=`ps -p $PID | grep -c "^$PID"`
94 if [ $torstat ]; then
95 echo "tor is running ($PID)"
96 else
97 echo "tor is not running (looks like it crashed, look for core? $PID)"
99 else
100 echo "tor is not running (exited gracefully)"
104 log)
105 cat $TORLOG
109 echo "Usage: $0 (start|stop|restart|status|log)"
110 exit 1
111 esac
113 exit $RETVAL