miguelfreitas / twister-seeder

twister dns seeder
51 stars 25 forks source link

running seeder as daemon #1

Open slr opened 9 years ago

slr commented 9 years ago

what is best practice to run Twister DNS seeder as a daemon on Debian/Ubuntu [to be compatible with privbind tool]?

I see this way (you should have root privileges):

privbind -u USER ~/twister-seeder/dnsseed -h NS.ADRESS.gTLD -n A.ADRESS.gTLD >foo.out 2>foo.err </dev/null & disown

but which method is the proper one actually?

gombadi commented 9 years ago

Hi

I am not sure about the proper way but I have mine running in a tmux session.

As root I setup a firewall rule to redirect udp port 53 to port 5353. iptables -t nat -A PREROUTING -p udp --dport 53 -j REDIRECT --to-port 5353

Then I run the seeder as an ordinary user with the -p 5353 option. Running in a tmux session also makes it easy to keep an eye on the process.

dryabov commented 9 years ago

I run it using screen:

screen
sudo ./dnsseed -h twisterseed.tk -n twisterseedns.tk
dryabov commented 9 years ago

As to DNS settings, they are

twisterseed.tk NS twisterseedns.tk

for twisterseed.tk, and

twisterseedns.tk A 146.185.185.41

for twisterseedns.tk (146.185.185.41 is IP address of the server where dnsseed is run).

slr commented 9 years ago

@gombadi for those ones who don't want to use iptables redirection for some reason, privbind can be good choice. I tested it.

@dryabov nice catch with same domain name for NS record.

so I would like to have some -d or --daemon option to run it as daemon.

dryabov commented 9 years ago

@slr I use two different domain names (twisterseed.tk and twisterseed ns.tk). I tried to setup 3rd-level domains (seed.somedomain.zz and seedns.somedomain.zz, like Miguel has on seed.twister.net.co), but it failed using default registrant's nameservers (either it is necessary to have own nameserver for somedomain.zz, or I made a mistake in setup of seed and seedns subdomains records).

slr commented 9 years ago

@dryabov oh, looks like I'm blind. too long conversation with my d-d display.

try to point your NS records to Yandex or Cloudflare and then do all setup there. I played with .tk registrant time ago, so I suppose this will turn out.

dryabov commented 9 years ago

Yes, Yandex DNS works well, and I'll use it as an alternative way (if twisterseed.tk will be blocked).

nitmir commented 9 years ago

I use this init script + iptables port redirection. It works greats

#!/bin/bash -e
### BEGIN INIT INFO
# Provides:          twister-seeder
# Required-Start:    $local_fs $remote_fs $network
# Required-Stop:     $local_fs $remote_fs $network
# Default-Start:     2 3 4 5
# Default-Stop:      0 1 6
# X-Interactive:     true
# Short-Description: Start/stop twister-seeder as a daemon
### END INIT INFO

# To start the script automatically at bootup type the following command
# update-rc.d twister-seeder defaults

USER=twister
NAME=twister-seeder
WORKINGDIR="/opt/twister/twister-seeder/"
DAEMON="/opt/twister/twister-seeder/dnsseed"
LOGFILE="/var/log/twister-seeder.log"
PIDFILE="/var/run/twister-seeder.pid"

HOST=twister.saphire.uk.to
NS=saphire.uk.to
PORT=5355
MBOX=root.saphire.uk.to  

ARGS="-h $HOST -n $NS -p $PORT -m $MBOX"

. /lib/lsb/init-functions

case $1 in
 start)
  #display to user that what is being started
  log_daemon_msg "Starting twister-seeder"
  #start the process and record record it's pid
  start-stop-daemon --start --background --chdir "$WORKINGDIR" --pidfile "$PIDFILE" --make-pidfile --startas /bin/bash --user $USER --chuid $USER -- -c "exec $DAEMON $ARGS >>$LOGFILE 2>&1"
  #output failure or success
  #info on how to interact with the torrent
  RET=$?
  if [[ $RET -eq 0 ]]; then
   log_success_msg "The process started successfully"
  else
   log_failure_msg "The process failed to start"
  fi
  exit $RET
 ;;

 status)
    status_of_proc -p $PIDFILE $DAEMON $NAME
 ;;

 stop)
  #display that we are stopping the process
  log_daemon_msg "Stopping twister-seeder"
  #stop the process using pid from start()
  start-stop-daemon --stop --pidfile "$PIDFILE" --user $USER --retry 30
  #output success or failure
  RET=$?
  if [[ $RET -eq 0 ]]; then
   log_success_msg "The process stopped successfully"
  else
   log_failure_msg "The process failed to stop"
  fi
  exit $RET
 ;;

 restart)
    "$0" stop && "$0" start;
 ;;

 *)
  # show the options
   echo "Usage: {start|stop|restart}"
;;
esac

For the log (twister-seeder is very very verbose) I use the logrotate configuration :

/var/log/twister-seeder.log {
        daily
        missingok
        rotate 4
        compress
        delaycompress
        notifempty
        create 640 twister adm
        su root adm
        sharedscripts
        postrotate
                if /etc/init.d/twister-seeder status > /dev/null ; then \
                    /etc/init.d/twister-seeder restart > /dev/null; \
                fi;
        endscript
}
slr commented 9 years ago

twister-seeder is very very verbose

I realized 20 minutes ago that with my method foo.out is placed in /home/ directory and occupies 7.2G already. so I also request -s option to shut it up.

slr commented 8 years ago

I see it's may be done with assigning of capability to bind a socket to privileged ports for dnsseed process.

sudo setcap CAP_NET_BIND_SERVICE=ep ~/twister-seeder/dnsseed

then you need only easy exec job for your favorite init daemon.

ghost commented 3 years ago

@slr how many disk space needed to run public seeder node for a long time? As I understand, the RAM will not be an issue, about 1Gb is enough? thanks