How-To: rTorrent with screen on Debian

rTorrent is a lightweight and stable torrent client with many functions.  It can turn your old, cheap linux box into a powerful torrent download server.

OK, let’s begin…

Install needed packages:

apt-get install rtorrent screen psmisc

Create rtorrent user:

useradd rtorrent

Create init file /etc/init.d/rtorrent containing:

#! /bin/sh
# rTorrent init script

case "$1" in
	echo "Starting rtorrent..."
    su rtorrent -c 'screen -dmS rtorrent rtorrent'
	echo "Stopping rtorrent..."
	killall -s 2 rtorrent
    echo "Usage: $0 {start|stop}"
    exit 1

exit 0

Make script executable and create rc.d symlinks:

chmod 755 /etc/init.d/rtorrent
update-rc.d rtorrent defaults

Start rtorrent:

/etc/init.d/rtorrent start

Try to log-in with rtorrent user and run:

screen -x

you should see rtorrent screen


Press “CTRL+a d” to exit screen and still logged-in as rtorrent user, copy example config file to home dir:

cp /usr/share/doc/rtorrent/examples/rtorrent.rc ~/.rtorrent.rc

Now, let’s configure it.

I will user folder /data/download/torrents/, which will contain 4 sub-folders:
watch/ – rtorrent will search here for .torrent files and auto-start downloading them
download/ – temporary directory for downloading
session/ – internal rtorrent session data
complete/ – when download is complete, files will be moved here

Create directories (as root):

mkdir -p /data/download/torrents/watch/
mkdir -p /data/download/torrents/download/
mkdir -p /data/download/torrents/session/
mkdir -p /data/download/torrents/complete/

chown -R rtorrent:rtorrent /data/download/torrents/
chmod -R 775 /data/download/torrents/

Open ~/.rtorrent.rc and add/change following lines:

directory = /data/download/torrents/download/
session = /data/download/torrents/session/

schedule = watch_directory,5,5,load_start=/data/download/torrents/watch/*.torrent
schedule = untied_directory,5,5,remove_untied=
on_finished = move_complete,"execute=mv,-u,$d.get_base_path=,/data/download/torrents/complete/ ;d.set_directory=/data/download/torrents/complete/"

rTorrent doesn’t yet support uPNP, so you’ll have to forward ports (both TCP and UDP) from router if your computer is not directly connected to internet… by default, it will open random port in range 6890-6999, but that can be changed with line:

port_range = 49200-49200

You can change seeding properties with this parameter (description is self-explanatory):

# Stop torrents when reaching upload ratio in percent,
# when also reaching total upload in bytes, or when
# reaching final upload ratio in percent.
# example: stop at ratio 2.0 with at least 200 MB uploaded, or else ratio 20.0
schedule = ratio,60,60,stop_on_ratio=200,200M,2000

Limit upload/download rate, so torrents won’t kill your internet connection :)
Values are in KiB.

upload_rate = 4
download_rate = 300

Those are the default values loaded at startup, you can change them in the program with a/z keys for upload and A/Z for download.

For better performance, you can limit number of peers:

max_peers = 50
max_peers_seed = 10

To change umask (file mode creation mask) for rtorrent process, change this parameter:

umask = 0002

OK, we’re done. Restart rtorrent (as root):

/etc/init.d/rtorrent stop
/etc/init.d/rtorrent start

To start a torrent download, just throw .torrent file in /data/download/torrents/watch/, and when download is done, file(s) will appear in /data/download/torrents/complete/
You can always connect with ssh to server as rtorrent user and run “screen -x” to see the status of downloading.


One thought on “How-To: rTorrent with screen on Debian

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s