#!/sbin/runscript # Copyright 1999-2005 Gentoo Foundation # Distributed under the terms of the GNU General Public License v2 opts="${opts} checkconfig reload" CONFDIR=/etc/tor tor='/usr/bin/tor' depend() { need net } checkconfig() { for i in {1,2,3,4,5,6,7,8}; do # first check that it exists if [ ! -f ${CONFDIR}/torrc-$i ] ; then eerror "You need to setup ${CONFDIR}/torrc-$i first" eerror "Example is in ${CONFFILE}.sample" return 1 fi done for foo in {1,2,3,4,5,6,7,8}; do # now verify whether the configuration is valid ${tor} --verify-config -f ${CONFDIR}/torrc-$foo > /dev/null 2>&1 if [ $? -eq 0 ] ; then einfo "Tor configuration (${CONFDIR}/torrc-$foo) is valid." return 0 else eerror "Tor configuration (${CONFDIR}/torrc-$foo) not valid." ${tor} --verify-config -f ${CONFDIR}/torrc-$foo return 1 fi done } start() { checkconfig || return 1 for c in {1,2,3,4,5,6,7,8}; do ebegin "Starting Tor-$c" ${tor} -f ${CONFDIR}/torrc-$c --quiet eend $? done } stop() { ebegin "Stopping Tor" /usr/bin/killall tor eend $? } reload() { checkconfig || return 1 ebegin "Reloading Tor configuration" ps ax | grep tor | grep -v init.d | grep -v rtorrent | grep -v hald | awk '{ print $1 }' | xargs kill sleep 2 for c in {1,2,3,4,5,6,7,8}; do ebegin "Restarting Tor-$c" ${tor} -f ${CONFDIR}/torrc-$c eend $? done eend $? }