3 # TOR control script designed to allow an easy command line interface
4 # to controlling The Onion Router
6 # The exit codes returned are:
7 # 0 - operation completed successfully
9 # 2 - Command not supported
10 # 3 - Could not be started
11 # 4 - Could not be stopped
17 # When multiple arguments are given, only the error from the _last_
21 # |||||||||||||||||||| START CONFIGURATION SECTION ||||||||||||||||||||
22 # -------------------- --------------------
23 # Name of the executable
26 # the path to your binary, including options if necessary
27 TORBIN
="@BINDIR@/$EXEC"
29 # the path to the configuration file
30 TORCONF
=@CONFDIR@
/torrc
32 # the path to your PID file
33 PIDFILE
=@LOCALSTATEDIR@
/run
/tor
/tor.pid
35 # The path to the log file
36 LOGFILE
=@LOCALSTATEDIR@
/log
/tor
/tor.log
38 # The path to the datadirectory
39 TORDATA
=@LOCALSTATEDIR@
/lib
/tor
41 # The USER and GROUP names:
42 # TORUSER and TORGROUP if defined in the environment, else LOGNAME and GROUP
47 TORARGS
="--pidfile $PIDFILE --log \"notice file $LOGFILE \" --runasdaemon 1"
48 TORARGS
="$TORARGS --datadirectory $TORDATA"
50 if [ "x$TORUSER" != "x" ]; then
51 TORARGS
="$TORARGS --user $TORUSER"
53 if [ "x$TORGROUP" != "x" ]; then
54 TORARGS
="$TORARGS --group $TORGROUP"
57 if [ -x /bin
/su
] ; then
59 elif [ -x /sbin
/su
] ; then
61 elif [ -x /usr
/bin
/su
] ; then
63 elif [ -x /usr
/sbin
/su
] ; then
69 # the command used to start
70 if [ "x$TORUSER" = "x" ]; then
71 START
="$TORBIN -f $TORCONF $TORARGS"
73 START
="$SUPROG -c \\"$TORBIN -f $TORCONF $TORARGS\\" $TORUSER"
77 # -------------------- --------------------
78 # |||||||||||||||||||| END CONFIGURATION SECTION ||||||||||||||||||||
82 if [ "x$ARGV" = "x" ] ; then
89 if [ -f $PIDFILE ] ; then
90 PID
=`/bin/cat $PIDFILE`
91 if [ "x$PID" != "x" ] ; then
92 if kill -0 $PID 2>/dev
/null
; then
93 STATUS
="$EXEC (pid $PID) running"
96 STATUS
="PID file ($PIDFILE) present, but $EXEC ($PID) not running"
100 STATUS
="$EXEC (pid $PID?) not running"
104 STATUS
="$EXEC apparently not running (no pid file)"
116 if [ $RUNNING -eq 1 ]; then
117 echo "$0 $ARG: $EXEC (pid $PID) already running"
121 echo "$0 $ARG: $EXEC started"
122 # Make sure it stayed up!
125 if [ $RUNNING -eq 0 ]; then
126 echo "$0 $ARG: $EXEC (pid $PID) quit unexpectedly"
129 echo "$0 $ARG: $EXEC could not be started"
134 if [ $RUNNING -eq 0 ]; then
135 echo "$0 $ARG: $STATUS"
138 if kill -15 $PID ; then
139 echo "$0 $ARG: $EXEC stopped"
142 if kill -9 $PID ; then
143 echo "$0 $ARG: $EXEC stopped"
145 echo "$0 $ARG: $EXEC could not be stopped"
149 # Make sure it really died!
152 if [ $RUNNING -eq 1 ]; then
153 echo "$0 $ARG: $EXEC (pid $PID) unexpectedly still running"
163 echo "usage: $0 (start|stop|restart|status|help)"
168 restart - stop and restart $EXEC if running or start if not running
169 status - tell whether $EXEC is running or not