aboutsummaryrefslogtreecommitdiff
path: root/contrib/torctl.in
diff options
context:
space:
mode:
authorNick Mathewson <nickm@torproject.org>2005-12-24 04:03:39 +0000
committerNick Mathewson <nickm@torproject.org>2005-12-24 04:03:39 +0000
commit221fc8d709c875086adb81215d4e3789b0811af3 (patch)
tree83f029523ec172f08c6eda7d06927a4e198ba522 /contrib/torctl.in
parent7db5ae23f559b0d6a539c3f98f6eca267dd0396b (diff)
downloadtor-221fc8d709c875086adb81215d4e3789b0811af3.tar
tor-221fc8d709c875086adb81215d4e3789b0811af3.tar.gz
Apply RPM-related cleanups from John Bashinski
svn:r5639
Diffstat (limited to 'contrib/torctl.in')
-rw-r--r--contrib/torctl.in146
1 files changed, 82 insertions, 64 deletions
diff --git a/contrib/torctl.in b/contrib/torctl.in
index 4faa8f0a0..4136bd943 100644
--- a/contrib/torctl.in
+++ b/contrib/torctl.in
@@ -4,15 +4,15 @@
# to controlling The Onion Router
#
# The exit codes returned are:
-# 0 - operation completed successfully
-# 1 -
-# 2 - Command not supported
-# 3 - Could not be started
-# 4 - Could not be stopped
-# 5 -
-# 6 -
-# 7 -
-# 8 -
+# 0 - operation completed successfully. For "status", tor running.
+# 1 - For "status", tor not running.
+# 2 - Command not supported
+# 3 - Could not be started or reloaded
+# 4 - Could not be stopped
+# 5 -
+# 6 -
+# 7 -
+# 8 -
#
# When multiple arguments are given, only the error from the _last_
# one is reported.
@@ -27,26 +27,30 @@ EXEC=tor
TORBIN="@BINDIR@/$EXEC"
#
# the path to the configuration file
-TORCONF=@CONFDIR@/torrc
+TORCONF="@CONFDIR@/torrc"
#
# the path to your PID file
-PIDFILE=@LOCALSTATEDIR@/run/tor/tor.pid
+PIDFILE="@LOCALSTATEDIR@/run/tor/tor.pid"
#
# The path to the log file
-LOGFILE=@LOCALSTATEDIR@/log/tor/tor.log
+LOGFILE="@LOCALSTATEDIR@/log/tor/tor.log"
#
# The path to the datadirectory
-TORDATA=@LOCALSTATEDIR@/lib/tor
+TORDATA="@LOCALSTATEDIR@/lib/tor"
#
-# The USER and GROUP names:
-# TORUSER and TORGROUP if defined in the environment, else LOGNAME and GROUP
-# respectively.
-TORUSER=
-TORGROUP=
-
-TORARGS="--pidfile $PIDFILE --log \"notice file $LOGFILE \" --runasdaemon 1"
+TORARGS="--pidfile $PIDFILE --log \"notice file $LOGFILE\" --runasdaemon 1"
TORARGS="$TORARGS --datadirectory $TORDATA"
+# If user and group names are set in the environment, then use them;
+# otherwise run as the invoking user (or whatever user the config
+# file says)... unless the invoking user is root. The idea here is to
+# let an unprivileged user run tor for her own use using this script,
+# while still providing for it to be used as a system daemon.
+if [ "x`id -u`" = "x0" ]; then
+ TORUSER=@TORUSER@
+ TORGROUP=@TORGROUP@
+fi
+
if [ "x$TORUSER" != "x" ]; then
TORARGS="$TORARGS --user $TORUSER"
fi
@@ -54,24 +58,10 @@ if [ "x$TORGROUP" != "x" ]; then
TORARGS="$TORARGS --group $TORGROUP"
fi
-if [ -x /bin/su ] ; then
- SUPROG=/bin/su
-elif [ -x /sbin/su ] ; then
- SUPROG=/sbin/su
-elif [ -x /usr/bin/su ] ; then
- SUPROG=/usr/bin/su
-elif [ -x /usr/sbin/su ] ; then
- SUPROG=/usr/sbin/su
-else
- SUPROG=/bin/su
-fi
-
-# the command used to start
-if [ "x$TORUSER" = "x" ]; then
- START="$TORBIN -f $TORCONF $TORARGS"
-else
- START="$SUPROG -c \\"$TORBIN -f $TORCONF $TORARGS\\" $TORUSER"
-fi
+# We no longer wrap the Tor daemon startup in an su when running as
+# root, because it's too painful to make the use of su portable.
+# Just let the daemon set the UID and GID.
+START="$TORBIN -f $TORCONF $TORARGS"
#
# -------------------- --------------------
@@ -86,23 +76,23 @@ fi
checkIfRunning ( ) {
# check for pidfile
PID=unknown
- if [ -f $PIDFILE ] ; then
+ if [ -f $PIDFILE ] ; then
PID=`/bin/cat $PIDFILE`
if [ "x$PID" != "x" ] ; then
- if kill -0 $PID 2>/dev/null ; then
- STATUS="$EXEC (pid $PID) running"
- RUNNING=1
- else
- STATUS="PID file ($PIDFILE) present, but $EXEC ($PID) not running"
- RUNNING=0
- fi
+ if kill -0 $PID 2>/dev/null ; then
+ STATUS="$EXEC (pid $PID) running"
+ RUNNING=1
+ else
+ STATUS="PID file ($PIDFILE) present, but $EXEC ($PID) not running"
+ RUNNING=0
+ fi
else
STATUS="$EXEC (pid $PID?) not running"
RUNNING=0
fi
else
- STATUS="$EXEC apparently not running (no pid file)"
- RUNNING=0
+ STATUS="$EXEC apparently not running (no pid file)"
+ RUNNING=0
fi
return
}
@@ -117,14 +107,14 @@ do
echo "$0 $ARG: $EXEC (pid $PID) already running"
continue
fi
- if $START ; then
+ if eval "$START" ; then
echo "$0 $ARG: $EXEC started"
- # Make sure it stayed up!
- /bin/sleep 1
- checkIfRunning
- if [ $RUNNING -eq 0 ]; then
- echo "$0 $ARG: $EXEC (pid $PID) quit unexpectedly"
- fi
+ # Make sure it stayed up!
+ /bin/sleep 1
+ checkIfRunning
+ if [ $RUNNING -eq 0 ]; then
+ echo "$0 $ARG: $EXEC (pid $PID) quit unexpectedly"
+ fi
else
echo "$0 $ARG: $EXEC could not be started"
ERROR=3
@@ -138,40 +128,68 @@ do
if kill -15 $PID ; then
echo "$0 $ARG: $EXEC stopped"
else
- /bin/sleep 1
- if kill -9 $PID ; then
- echo "$0 $ARG: $EXEC stopped"
- else
- echo "$0 $ARG: $EXEC could not be stopped"
- ERROR=4
- fi
+ /bin/sleep 1
+ if kill -9 $PID ; then
+ echo "$0 $ARG: $EXEC stopped"
+ else
+ echo "$0 $ARG: $EXEC could not be stopped"
+ ERROR=4
+ fi
fi
# Make sure it really died!
/bin/sleep 1
checkIfRunning
if [ $RUNNING -eq 1 ]; then
echo "$0 $ARG: $EXEC (pid $PID) unexpectedly still running"
+ ERROR=4
fi
;;
restart)
$0 stop start
;;
+ reload)
+ if [ $RUNNING -eq 0 ]; then
+ echo "$0 $ARG: $STATUS"
+ continue
+ fi
+ if kill -1 $PID; then
+ /bin/sleep 1
+ echo "$EXEC (PID $PID) reloaded"
+ else
+ echo "Can't reload $EXEC"
+ ERROR=3
+ fi
+ ;;
status)
echo $STATUS
+ if [ $RUNNING -eq 1 ]; then
+ ERROR=0
+ else
+ ERROR=1
+ fi
;;
- *)
+ log)
+ cat $LOGFILE
+ ;;
+ help)
echo "usage: $0 (start|stop|restart|status|help)"
/bin/cat <<EOF
start - start $EXEC
stop - stop $EXEC
restart - stop and restart $EXEC if running or start if not running
+reload - cause the running process to reinitialize itself
status - tell whether $EXEC is running or not
+log - display the contents of the log file
help - this text
EOF
+ ERROR=0
+ ;;
+ *)
+ $0 help
ERROR=2
- ;;
+ ;;
esac