rc.bittorrent

This is an init script to run a BitTorrent client as a daemon. It was originally written by Kreiger and it's slightly modified by Blenda.

The script is useful for automatic torrent downloading or putting up a dedicated seed for your torrents. It uses the btlaunchmany script availible from the original BitTorrent distribution or BitTornado.

All meta files (.torrent) that are placed in BTDIR will automatically be downloaded. If the objects to be downloaded already are present in BTDIR, btlaunchmany will start to seed them.

For more info on btlaunchmany and it's options, se the man page.

Comments, corrections and improvements are welcome! You can also contact Blenda by e-mail at blenda@handgranat.org.

If you're using Fedora there are init scripts for tracker and seeder in the bittorrent package.

Script options

BTDIR
This is the directory where you put your meta files (.torrent). If you're seeding, the objects to be seeded can be (sym)linked if you store them in some other directory.
MAX_UPLOAD_RATE
Maximal upload rate given in kB/s. 0 = no limit, -1 = automatic.
MINPORT/MAXPORT
Set port range to listen to. If you are behind NAT you should open this port range.
SUPER_SEEDER
If you're running a dedicated seed you might want to use BitTorrents special upload-efficiency-maximizing routines. I removed this option since in BitTorrent-4.x or greater (from the original distribution), the main seeding code is improved and thus making the super-seed mode obsolete.
IP
If you are running the BT client on the same LAN/machine as your tracker you probably should report a fully qualified domain name here.

Bugs

The BT client should not be started if an instance is already running.

Unfortuneately this script does not seem to work properly on my Debian system. The real PID of the btlaunchmany process will be $PIDFILE + 1, so the script cannot be used to kill the daemon. —Blenda

Since btlaunchmany outputs progress indications very often the log files tend to grow huge quite fast. This consumes disk space and makes the log file hard to survey.

If the log file is deleted when the daemon is running, a new one will not be created.

See also

<insert list of similar scripts here>

The script

#!/bin/sh

# This is an init script to start a BitTorrent client as a daemon.
# The script is originally from Kreiger (but slightly modified) -- se his web site at http://kreiger.linuxgods.com/
# More info at http://handgranat.org/rc.bittorrent

PIDFILE=/var/run/btlaunchmany.pid
BTDIR=/foobar
MAX_UPLOAD_RATE=0
LOGFILE=$BTDIR/torrents.log
MINPORT=10000
MAXPORT=60000
IP=hostname.domain 

torrents_start() {
    btlaunchmany $BTDIR --ip $IP --max_upload_rate $MAX_UPLOAD_RATE --minport $MINPORT --maxport $MAXPORT > $LOGFILE &
    echo $! > $PIDFILE
}

torrents_stop() {
    if [ -r $PIDFILE ]; then
    	PID=`cat $PIDFILE`
	kill $PID 2> /dev/null
	for ((I=0 ; I < 10 ; I++)); do
	    kill -0 $PID || break
    	    sleep 1
	done
	if kill -0 $PID; then
	    kill -9 $PID
	fi
	rm $PIDFILE
    fi
}


case "$1" in
start)
    torrents_start
    ;;
stop)
    torrents_stop
    ;;
restart)
    torrents_stop
    torrents_start
    ;;
force-reload)
    torrents_stop
    torrents_start
    ;;
*)    
    echo "Usage: $0 {start|stop|restart|force-reload}"
    ;;
esac

Similar scripts

Se även datorer.