All pastes #751657 Raw Edit

Miscellany

public text v1 · immutable
#751657 ·published 2007-10-27 16:26 UTC
rendered paste body
#!/bin/bash
# 2006.02.11 tor-0.1.1.13.alpha
# TOR control script designed to allow an easy command line interface
# to controlling The Onion Router
#
# The exit codes returned are:
#       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

. /etc/sysconfig/rc
. $rc_functions

# --------------------                              --------------------
# user and group we run
TORUSER=tor
TORGROUP=tor
#
# Name of the executable
EXEC="tor"
#
# the path to your binary, including options if necessary
TORBIN="/usr/local/bin/$EXEC"
#
# the path to the configuration file
TORCONF="/usr/local/etc/tor/torrc"
#
# PID
PID=""
#
# PIDFILE
PIDFILE="/var/run/tor.pid"
#
# The path to the log file
LOGFILE="/var/log/tor/tor.log"
#
# The path to the datadirectory
TORDATA="/var/lib/tor"
#
#TORARGS="--pidfile $PIDFILE --log \"debug file $LOGFILE\" --runasdaemon 1"
TORARGS="--pidfile $PIDFILE --log \"debug file $LOGFILE\" --runasdaemon 0"

TORARGS="$TORARGS --datadirectory $TORDATA"
TORARGS="$TORARGS --user $TORUSER"
TORARGS="$TORARGS --group $TORGROUP"

STARTTOR="$TORBIN -f $TORCONF $TORARGS > /dev/null &"

# some checks for us
if [ ! -x $TORBIN  ] ; then exit 0 ;fi
if [ ! -f $TORCONF ] ; then exit 0 ;fi

status() {
	local PID=`/sbin/pidof -s ${TORBIN}`
	if [ ! -z "${PID}" ]; then
		echo "${TORBIN} running, PID ${PID}"
	else
		echo "${TORBIN} not running."
	fi
}

start () {
	# start daemon
	local PID=`/sbin/pidof -s ${TORBIN}`
	if [ -z "${PID}" ]; then
		echo "Starting ${TORBIN}"
		eval ${STARTTOR}
		evaluate_retval
	else
		echo "$TORBIN running, PID ${PID}"
	fi
}

stop () {
	# stop daemon
	local PID=`/sbin/pidof -s ${TORBIN}`

	if [ ! -z "${PID}" ]; then
		echo "Stopping ${TORBIN}"
		kill -TERM ${PID}
		evaluate_retval
	else
		echo "${TORBIN} not running."
	fi
}

case "$1" in
	start)
		start
		;;
	stop)
		stop
		;;
	restart)
		stop
		sleep 1
		start
		;;
	status)
		status
	;;
  	*)
		echo $"Usage: $0 {start|stop|restart|status}"
		exit 1
esac