aboutsummaryrefslogtreecommitdiff
path: root/contrib/tor.sh.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/tor.sh.in
parent7db5ae23f559b0d6a539c3f98f6eca267dd0396b (diff)
downloadtor-221fc8d709c875086adb81215d4e3789b0811af3.tar
tor-221fc8d709c875086adb81215d4e3789b0811af3.tar.gz
Apply RPM-related cleanups from John Bashinski
svn:r5639
Diffstat (limited to 'contrib/tor.sh.in')
-rw-r--r--contrib/tor.sh.in127
1 files changed, 40 insertions, 87 deletions
diff --git a/contrib/tor.sh.in b/contrib/tor.sh.in
index 2fc35b841..e9e604dd5 100644
--- a/contrib/tor.sh.in
+++ b/contrib/tor.sh.in
@@ -1,28 +1,35 @@
#!/bin/sh
#
-#tor The Onion Router
+# tor The Onion Router
+#
+# Startup/shutdown script for tor. This is a wrapper around torctl;
+# torctl does the actual work in a relatively system-independent, or at least
+# distribution-independent, way, and this script deals with fitting the
+# whole thing into the conventions of the particular system at hand.
+# This particular script is written for Red Hat/Fedora Linux, and may
+# also work on Mandrake, but not SuSE.
+#
+# These next couple of lines "declare" tor for the "chkconfig" program,
+# originally from SGI, used on Red Hat/Fedora and probably elsewhere.
#
# chkconfig: 2345 90 10
-# description: Onion Router
-
-TORUSER=
-TORGROUP=
-TORBIN=@BINDIR@/tor
-TORPID=@LOCALSTATEDIR@/run/tor/tor.pid
-TORLOG=@LOCALSTATEDIR@/log/tor/tor.log
-TORDATA=@LOCALSTATEDIR@/lib/tor
+# description: Onion Router - A low-latency anonymous proxy
+#
-TORCONF=@CONFDIR@/torrc
-# Strictly speaking, we don't need to su if we have --user and --group.
-# "Belt and suspenders," says jbash.
-TORARGS="--pidfile $TORPID --log \"notice file $TORLOG \" --runasdaemon 1 --datadirectory $TORDATA"
-if [ "x$TORUSER" != "x" ]; then
- TORARGS="$TORARGS --user $TORUSER"
+# Library functions
+if [ -f /etc/rc.d/init.d/functions ]; then
+ . /etc/rc.d/init.d/functions
+elif [ -f /etc/init.d/functions ]; then
+ . /etc/init.d/functions
fi
-if [ "x$TORGROUP" != "x" ]; then
- TORARGS="$TORARGS --group $TORGROUP"
-fi
-RETVAL=0
+
+TORCTL=@BINDIR@/torctl
+
+# torctl will use these environment variables
+TORUSER=@TORUSER@
+export TORUSER
+TORGROUP=@TORGROUP@
+export TORGROUP
if [ -x /bin/su ] ; then
SUPROG=/bin/su
@@ -39,87 +46,33 @@ fi
case "$1" in
start)
- if [ -f $TORPID ]; then
- echo "tor appears to be already running (pid file exists)"
- echo "Maybe you should run: $0 restart ?"
- RETVAL=1
- else
- echo -n "Starting tor..."
- if [ "x$TORUSER" = "x" ]; then
- $TORBIN -f $TORCONF $TORARGS
- else
- $SUPROG -c "$TORBIN -f $TORCONF $TORARGS" $TORUSER
- fi
- RETVAL=$?
- if [ $RETVAL -eq 0 ]; then
- echo " ok"
- else
- echo " ERROR!"
- fi
- fi
+ action $"Starting tor:" $TORCTL start
+ RETVAL=$?
;;
stop)
- if [ -f $TORPID ]; then
- echo -n "Killing tor..."
- kill `cat $TORPID`
- RETVAL=$?
- if [ $RETVAL -eq 0 ]; then
- echo " ok"
- else
- echo " ERROR!"
- fi
- else
- echo "Unable to kill tor: $TORPID does not exist. Assuming already dead."
- RETVAL=0
- fi
- ;;
-
- reload)
- if [ -f $TORPID ]; then
- echo -n "Sending HUP to tor..."
- kill -HUP `cat $TORPID`
- RETVAL=$?
- if [ $RETVAL -eq 0 ]; then
- echo " ok"
- else
- echo " ERROR!"
- fi
- else
- echo "Unable to kill tor: $TORPID does not exist"
- RETVAL=1
- fi
+ action $"Stopping tor:" $TORCTL stop
+ RETVAL=$?
;;
restart)
- $0 stop
- if [ -f $TORPID ]; then
- rm -f $TORPID
- fi
- $0 start
+ action $"Restarting tor:" $TORCTL restart
+ RETVAL=$?
;;
- status)
- PID=`cat $TORPID 2>/dev/null`
- if [ "$PID" != "" ]; then
- torstat=`ps -p $PID | grep -c "^$PID"`
- if [ $torstat ]; then
- echo "tor is running ($PID)"
- else
- echo "tor is not running (looks like it crashed, look for core? $PID)"
- fi
- else
- echo "tor is not running (exited gracefully)"
- fi
+ reload)
+ action $"Reloading tor:" $TORCTL reload
+ RETVAL=$?
;;
- log)
- cat $TORLOG
+ status)
+ $TORCTL status
+ RETVAL=$?
;;
*)
- echo "Usage: $0 (start|stop|restart|status|log)"
- exit 1
+ echo "Usage: $0 (start|stop|restart|reload|status)"
+ RETVAL=1
esac
exit $RETVAL