Using rtorrent with screen
rtorrent is a frugal but feature rich command line torrent client and so is ideal for using on a headless server over ssh. Setting up an instance of rtorrent inside a screen session allows you to log off from the server and still have your torrents downloading. So you can be downloading 24/7 on your less power-hungry server rather than on your main mega-Watt guzzling gaming BEAST.
First lets install rtorrent on your server:
$ sudo apt-get install rtorrent
Typing rtorrent at the command line will now start the program and you can view details such as what speed your torrents are downloading at, and their progress. Start a new torrent download by pressing backspace and entering the file path to a .torrent file. The cursor keys will select different torrents and crtl d will stop an active torrent, crtl s starts an inactive one. More info about rtorrent and its capabilities can be found at the rtorrent wiki here and at K.Mandla’s blog.
Before you can start downloading though you’ll need to open the .rtorrent.rc config file that has been created in your home directory and configure it for your system:
$ nano .rtorrentrc
My .rtorrentrc file is listed below:
# This is an example resource file for rTorrent. Copy to
# ~/.rtorrent.rc and enable/modify the options as needed. Remember to
# uncomment the options you wish to enable.
# Maximum and minimum number of peers to connect to per torrent.
min_peers = 40
max_peers = 100
# Same as above but for seeding completed torrents (-1 = same as downloading)
min_peers_seed = 10
max_peers_seed = 50
# Maximum number of simultanious uploads per torrent.
max_uploads = 2
# Global upload and download rate in KiB. “0″ for unlimited.
download_rate = 150
upload_rate =25
# Default directory to save the downloaded torrents.
directory = /media/iomega1/rtorrent/downloads/
# Default session directory. Make sure you don’t run multiple instance
# of rtorrent using the same session directory. Perhaps using a
# relative path?
session = /media/iomega1/rtorrent/session
# Watch a directory for new torrents, and stop those that have been
# deleted.
schedule = watch_directory,5,5,load_start=/media/iomega1/raydocs/Bobby/FinTorrents/torrentfiles/*.torrent
schedule = untied_directory,5,5,stop_untied=
# When the torrent finishes, it executes “mv -n <base_path> ~/Download/”
# and then sets the destination directory to “~/Download/”. (0.7.7+)
on_finished = move_complete,”execute=mv,-u,$d.get_base_path=,/media/iomega1/raydocs/Bobby/FinTorrents/ ;d.set_directory=~/media/iomega1/raydocs/Bobby/FinTorrents/“
# Close torrents when diskspace is low.
schedule = low_diskspace,5,60,close_low_diskspace=100M
# 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″
# After deleting torrents from that list .torrent files will be deleted too;
schedule = untied_directory,5,5,stop_untied=
# The ip address reported to the tracker.
#ip = 127.0.0.1
#ip = rakshasa.no
# The ip address the listening socket and outgoing connections is
# bound to.
#bind = 127.0.0.1
#bind = rakshasa.no
# Port range to use for listening.
#port_range = 6890-6999
# Start opening ports at a random position within the port range.
#port_random = no
# Check hash for finished torrents. Might be usefull until the bug is
# fixed that causes lack of diskspace not to be properly reported.
check_hash = no
# Set whetever the client should try to connect to UDP trackers.
#use_udp_trackers = yes
# Alternative calls to bind and ip that should handle dynamic ip’s.
#schedule = ip_tick,0,1800,ip=rakshasa
#schedule = bind_tick,0,1800,bind=rakshasa
# Encryption options, set to none (default) or any combination of the following:
# allow_incoming, try_outgoing, require, require_RC4, enable_retry, prefer_plaintext
#
# The example value allows incoming encrypted connections, starts unencrypted
# outgoing connections but retries with encryption if they fail, preferring
# plaintext to RC4 encryption after the encrypted handshake
#
# encryption = allow_incoming,enable_retry,prefer_plaintext
# Enable DHT support for trackerless torrents or when all trackers are down.
# May be set to “disable” (completely disable DHT), “off” (do not start DHT),
# “auto” (start and stop DHT as needed), or “on” (start DHT immediately).
# The default is “off”. For DHT to work, a session directory must be defined.
#
# dht = auto
# UDP port to use for DHT.
#
# dht_port = 6881
# Enable peer exchange (for torrents not marked private)
#
# peer_exchange = yes
#
# Do not modify the following parameters unless you know what you’re doing.
#
# Hash read-ahead controls how many MB to request the kernel to read
# ahead. If the value is too low the disk may not be fully utilized,
# while if too high the kernel might not be able to keep the read
# pages in memory thus end up trashing.
#hash_read_ahead = 10
# Interval between attempts to check the hash, in milliseconds.
#hash_interval = 100
# Number of attempts to check the hash while using the mincore status,
# before forcing. Overworked systems might need lower values to get a
# decent hash checking rate.
#hash_max_tries = 10
In the above configuration file you can see that while my torrents are being downloaded they are stored in, /media/iomega1/rtorrent/downloads/. Then when the torrent is finished the file is moved to another folder, /media/iomega1/raydocs/Bobby/FinTorrents/. This folder is accessible on my main computer as it is mounted as a Samba share, so I can quickly see when a torrent is finished without having to ssh into my server to check. Also when I want to start a new torrent download while on my main computer I just paste the *.torrent file into this ‘watch’ directory, also on the samba share:
# Watch a directory for new torrents, and stop those that have been
# deleted.
schedule = watch_directory,5,5,load_start=/media/iomega1/raydocs/Bobby/FinTorrents/torrentfiles/*.torrent
* * *
Now to start using screen with rtorrent type first we’ll install screen with :
$ sudo apt-get install screen
Then to start a new screen session type:
$ screen
This will open a new screen session. Press return as asked and at the new command line inside the screen instance we can start rtorrent and start downloading as normal by typing:
$ rtorrent
Then when you have rtorrent running as you want it you can press crtl-a and then ctrl-d to exit the screen and return to the command line, while leaving the screen session running in the background.
To list all running instances of screen type:
$ screen -ls
to resume a listed screen session type:
$ screen -r “screen number“
or
$ screen -r
if there is only one screen running