#! /bin/sh
#
# ttdnsd    The Tor TCP DNS Daemon
#
# This initscript runs a chrooted ttdnsd process and it makes recursive TCP
# DNS requests through the Tor network.

# This script is a modified version of Jacob Appelbaum's /etc/init.d/ttdnsd
# for use on Slackware.

# Author: Marco Bonetti <sid77@slackware.it>

# Do NOT "set -e"

NAME=ttdnsd
DAEMON=/usr/sbin/$NAME
PIDFILE=/var/run/ttdnsd.pid
TSOCKS_CONF_FILE=tsocks.conf
export TSOCKS_CONF_FILE

# Read configuration variable file if it is present
[ -r /etc/default/$NAME ] && . /etc/default/$NAME

# This will be overloaded by $DEFAULTS
DAEMON_ARGS="-P $PIDFILE -f /etc/ttdnsd.conf $DEFAULTS"

start() {
  $DAEMON $DAEMON_ARGS
}

stop() {
  kill `cat $PIDFILE`
}

reload() {
  kill -s HUP `cat $PIDFILE`
}

case "$1" in
  start)
    start
    ;;
  stop)
    stop
    ;;
  reload)
    reload
    ;;
  restart|force-reload)
    stop
    sleep 1
    start
    ;;
  *)
    echo "Usage: $0 (start|stop|reload|restart|force-reload)"
    ;;
esac