aboutsummaryrefslogtreecommitdiff
path: root/contrib/tor.sh.in
diff options
context:
space:
mode:
authorRoger Dingledine <arma@torproject.org>2004-02-17 00:55:29 +0000
committerRoger Dingledine <arma@torproject.org>2004-02-17 00:55:29 +0000
commit22b3d10aede96b33a49b5c6f7298cc2ad432df9a (patch)
treec8e391b1d7db3c25136990598df470266eed64f6 /contrib/tor.sh.in
parent153d198a4db6eb762be557a10f2d69cb50df9004 (diff)
downloadtor-22b3d10aede96b33a49b5c6f7298cc2ad432df9a.tar
tor-22b3d10aede96b33a49b5c6f7298cc2ad432df9a.tar.gz
move the tor init script into contrib/
svn:r1067
Diffstat (limited to 'contrib/tor.sh.in')
-rw-r--r--contrib/tor.sh.in76
1 files changed, 76 insertions, 0 deletions
diff --git a/contrib/tor.sh.in b/contrib/tor.sh.in
new file mode 100644
index 000000000..ecf3cb32d
--- /dev/null
+++ b/contrib/tor.sh.in
@@ -0,0 +1,76 @@
+#!/bin/sh
+
+TORBIN=@BINDIR@/tor
+TORPID=@LOCALSTATEDIR@/run/tor.pid
+TORLOG=@LOCALSTATEDIR@/log/tor/tor.log
+TORCONF=@CONFDIR@/torrc
+TORARGS="--pidfile $TORPID --logfile $TORLOG --runasdaemon 1"
+RETVAL=0
+
+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..."
+ $TORBIN -f $TORCONF $TORARGS
+ RETVAL=$?
+ if [ $RETVAL -eq 0 ]; then
+ echo " ok"
+ else
+ echo " ERROR!"
+ fi
+ fi
+ ;;
+
+ 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"
+ RETVAL=1
+ fi
+ ;;
+
+ restart)
+ $0 stop
+ if [ -f $TORPID ]; then
+ rm -f $TORPID
+ fi
+ $0 start
+ ;;
+
+ 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
+ ;;
+
+ log)
+ cat $TORLOG
+ ;;
+
+ *)
+ echo "Usage: $0 (start|stop|restart|status|log)"
+ exit 1
+esac
+
+exit $RETVAL