Blob Blame History Raw
#!/bin/bash
#
# Init file for tor - An Anonymizing overlay network for TCP
#
# chkconfig: - 99 01
# description:   An Anonymizing overlay network for TCP
#
### BEGIN INIT INFO
# Default-Stop:		0 1 2 6
# Short-Description:	An Anonymizing overlay network for TCP
# Description:		An Anonymizing overlay network for TCP
# Required-Start:	$network
# Should-Start:		$syslog $time $remote_fs
### END INIT INFO

. /lib/lsb/init-functions

f=/etc/sysconfig/tor

TOR_SHUTDOWN_WAIT=30
TOR_OPTS=--quiet
TOR_PIDFILE=/var/run/tor/tor.pid
TOR_USER=toranon
test ! -r "$f" || . "$f"

prog="/usr/bin/tor"

lockfile=/var/lock/subsys/tor
pidfile=$TOR_PIDFILE

start() {
    echo -n $"Starting $prog: "

    start_daemon $prog --PIDFile "$pidfile" --RunAsDaemon 1 $TOR_OPTS
    rc=$?
    if test $rc -eq 0 && touch $lockfile; then
	log_success_msg
    else
	log_failure_msg
    fi

    return $rc
}

stop() {
    echo -n $"Stopping $prog: "
    if ! killproc -p "$pidfile" $prog -INT; then
	log_failure_msg
    else
	cnt=$TOR_SHUTDOWN_WAIT
	while let '--cnt > 0' && killproc -p "$pidfile" $prog -0; do
	    sleep 1
	done

	if test $cnt -ne 0 || killproc -p "$pidfile" $prog; then
	    log_success_msg
	else
	    log_failure_msg
	fi
    fi

    rm -f $pidfile $lockfile
}

restart() {
    stop
    start
}

reload() {
    echo -n $"Reloading $prog: "
    killproc -p "$pidfile" $prog -HUP && log_success_msg || log_failure_msg
}

status() {
    pidofproc -p "$pidfile" "$prog" >/dev/null 2>&1
    rc=$?
    case $rc in
      (0) echo $"$prog is running";;
      (1) echo $"program is dead and /var/run pid file exists";;
      (2) echo $"program is dead and /var/lock lock file exists";;
      (3) echo $"program is not running";;
      (4) echo $"program or service status is unknown";;
      (*) echo $"status $rc of $prog";;
    esac

    return $rc
}

case $1 in
    (start|stop|reload|status|restart)
	$1
	;;
    (force-reload)
	restart
	;;
    (condrestart|try-restart)
	if [ -f $lockfile ]; then
	    restart
	fi
	;;
    (*)
	echo $"Usage: $0 {start|stop|force-reload|reload|try-restart|status}"
	exit 3
esac