Running multiple instances of rtorrent

I really like rtorrent.  It does a few things and does those few things very well without the needless drama and complexity of most bittorrent clients.  Combined with screen, flexget and configuring it to listen on an incoming directory, it becomes extremely powerful and uses barely any resources.

Unfortunately, having control of what amount of upstream bandwidth different torrents can use doesn’t appear to be possible and it becomes impractical trying to manage many torrents from multiple trackers I find.  My solution I’ve cooked up is to spawn a screen session with two (or three or four) separate instances of rtorrent running separate config files.

Rtorrent configuration

At minimum, the rtorrent config files need to specify separate port ranges and unique session directories:

.rtorrent1.rc:
session = /home/user/.session
port_range = 6881-6935

.rtorrent2.rc:
session = /home/user/.session2
port_range = 6936-6999

Now at this point, I can also configure separate upload/download throttling, disable/enable DHT, etc, differently for each instance.  Let’s make the second instance stingy with our precious upstream bandwidth:

.rtorrent2.rc
upload_rate = 30

Screen trickery

Here’s what the screenrc file to run this mess looks like:

sessionname rtorrent
screen -t rtorrent1 rtorrent -n -o import=/home/user/.rtorrent1.rc
screen -t rtorrent2 rtorrent -n -o import=/home/user/.rtorrent2.rc

Pretty straight forward.  Running screen -d -m -c /home/user/.screenrc_rtorrent opens a detached screen session with two windows, spawning two rtorrents with different configuration files.

Init script

Under Arch, I have the screen session launch on start-up using this simple little init script:

/etc/rc.d/rtorrent:

#!/bin/bash

. /etc/rc.conf
. /etc/rc.d/functions

case "$1" in
	start)
		stat_busy "Starting rtorrent"
		if [ -e /home/user/.session/rpc.socket ]; then
			rm -f /home/user/.session/rpc.socket
		fi
		if [ -e /home/tv/.session2/rpc.socket ]; then
			rm -f /home/tv/.session2/rpc.socket
		fi
		su user -c 'screen -d -m -c /home/user/.screenrc_rtorrent' &> /dev/null
		if [ $? -gt 0 ]; then
			stat_fail
		else
			add_daemon rtorrent
			stat_done
		fi
	;;
	stop)
		stat_busy "Stopping rtorrent"
		killall -s 30 rtorrent
		if [ $? -gt 0 ]; then
			stat_fail
		else
			rm_daemon rtorrent
			stat_done
		fi
	;;
	restart)
		$0 stop
		sleep 1
		$0 start
	;;
	*)
		echo "usage: $0 {start|stop|restart}"
esac
exit 0

Now rtorrent is more awesome because there are two of them.  Way to go us!

Edit: Here’s a way more elegant solution that uses throttle and ratio groups instead of spawning multiple instances: https://github.com/avar/leech/blob/master/.rtorrent.rc

One Comment

  1. pyroscope
    Posted 2011/12/14 at 14:58 | Permalink | Reply

    To handle multi-tracker setups easily, especially when you cross-seed the same data under the same name…

Leave a comment