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 # the command used to start
58 if [ "x$TORUSER" = "x" ]; then
59 START
="$TORBIN -f $TORCONF $TORARGS"
61 START
="/bin/su -c \\"$TORBIN -f $TORCONF $TORARGS\\" $TORUSER"
65 # -------------------- --------------------
66 # |||||||||||||||||||| END CONFIGURATION SECTION ||||||||||||||||||||
70 if [ "x$ARGV" = "x" ] ; then
77 if [ -f $PIDFILE ] ; then
78 PID
=`/bin/cat $PIDFILE`
79 if [ "x$PID" != "x" ] ; then
80 if kill -0 $PID 2>/dev
/null
; then
81 STATUS
="$EXEC (pid $PID) running"
84 STATUS
="PID file ($PIDFILE) present, but $EXEC ($PID) not running"
88 STATUS
="$EXEC (pid $PID?) not running"
92 STATUS
="$EXEC apparently not running (no pid file)"
104 if [ $RUNNING -eq 1 ]; then
105 echo "$0 $ARG: $EXEC (pid $PID) already running"
109 echo "$0 $ARG: $EXEC started"
110 # Make sure it stayed up!
113 if [ $RUNNING -eq 0 ]; then
114 echo "$0 $ARG: $EXEC (pid $PID) quit unexpectedly"
117 echo "$0 $ARG: $EXEC could not be started"
122 if [ $RUNNING -eq 0 ]; then
123 echo "$0 $ARG: $STATUS"
126 if kill -15 $PID ; then
127 echo "$0 $ARG: $EXEC stopped"
130 if kill -9 $PID ; then
131 echo "$0 $ARG: $EXEC stopped"
133 echo "$0 $ARG: $EXEC could not be stopped"
137 # Make sure it really died!
140 if [ $RUNNING -eq 1 ]; then
141 echo "$0 $ARG: $EXEC (pid $PID) unexpectedly still running"
151 echo "usage: $0 (start|stop|restart|status|help)"
156 restart - stop and restart $EXEC if running or start if not running
157 status - tell whether $EXEC is running or not