Note that authentication arguments are optional
[tor.git] / contrib / tor.sh.in
blob2fc35b84104a6c1bc2fef13f3f67a90270b6ae7d
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 if [ -x /bin/su ] ; then
28 SUPROG=/bin/su
29 elif [ -x /sbin/su ] ; then
30 SUPROG=/sbin/su
31 elif [ -x /usr/bin/su ] ; then
32 SUPROG=/usr/bin/su
33 elif [ -x /usr/sbin/su ] ; then
34 SUPROG=/usr/sbin/su
35 else
36 SUPROG=/bin/su
39 case "$1" in
41 start)
42 if [ -f $TORPID ]; then
43 echo "tor appears to be already running (pid file exists)"
44 echo "Maybe you should run: $0 restart ?"
45 RETVAL=1
46 else
47 echo -n "Starting tor..."
48 if [ "x$TORUSER" = "x" ]; then
49 $TORBIN -f $TORCONF $TORARGS
50 else
51 $SUPROG -c "$TORBIN -f $TORCONF $TORARGS" $TORUSER
53 RETVAL=$?
54 if [ $RETVAL -eq 0 ]; then
55 echo " ok"
56 else
57 echo " ERROR!"
62 stop)
63 if [ -f $TORPID ]; then
64 echo -n "Killing tor..."
65 kill `cat $TORPID`
66 RETVAL=$?
67 if [ $RETVAL -eq 0 ]; then
68 echo " ok"
69 else
70 echo " ERROR!"
72 else
73 echo "Unable to kill tor: $TORPID does not exist. Assuming already dead."
74 RETVAL=0
78 reload)
79 if [ -f $TORPID ]; then
80 echo -n "Sending HUP to tor..."
81 kill -HUP `cat $TORPID`
82 RETVAL=$?
83 if [ $RETVAL -eq 0 ]; then
84 echo " ok"
85 else
86 echo " ERROR!"
88 else
89 echo "Unable to kill tor: $TORPID does not exist"
90 RETVAL=1
94 restart)
95 $0 stop
96 if [ -f $TORPID ]; then
97 rm -f $TORPID
99 $0 start
102 status)
103 PID=`cat $TORPID 2>/dev/null`
104 if [ "$PID" != "" ]; then
105 torstat=`ps -p $PID | grep -c "^$PID"`
106 if [ $torstat ]; then
107 echo "tor is running ($PID)"
108 else
109 echo "tor is not running (looks like it crashed, look for core? $PID)"
111 else
112 echo "tor is not running (exited gracefully)"
116 log)
117 cat $TORLOG
121 echo "Usage: $0 (start|stop|restart|status|log)"
122 exit 1
123 esac
125 exit $RETVAL