Tech Journal Back to Tech Journal

How did you set up rtorrent as a headless RSS-based downloader?

It was quite simple. I did the following steps:

  1. Set up lighttpd (which required PCRE), using the following /etc/lighttpd/lighttpd.conf configuration file:
    server.document-root = "/var/www/lighttpd/"
    server.port = 2409
    server.username = "lighttpd"
    server.groupname = "lighttpd"
    server.modules = (
    #       "mod_proxy_backend_scgi",
    mimetype.assign = (
      ".html" => "text/html",
      ".txt" => "text/plain",
      ".jpg" => "image/jpeg",
      ".png" => "image/png"
    static-file.exclude-extensions = ( ".fcgi", ".php", ".rb", "~", ".inc" )
    index-file.names = ( "index.html" )
    accesslog.filename = "/var/log/lighttpd/lighttpd.access.log"
    server.errorlog = "/var/log/lighttpd/lighttpd.error.log"
    ####### for rTorrent #####
    scgi.server = (
                    "/RPC2" =>
                      ( "" =>
                          "socket" => "/home/shalom/.rtorrent/rpc.socket",
                          "check-local" => "disable",
                          "disable-time" => 0,  # don't disable scgi if connection fails
    # for more info, see default config:
  2. Set up libtorrent, which required sig++-2.0 and a softlink between that library's location in /usr/lib to /usr/local/lib)
  3. Compiled rtorrent with --with-xmlrpc.
  4. Got nTorrent as a Java-based, cross-platform, GUI for controlling rtorrent via XML-RPC.
  5. Using rules from, I build a configuration file to move finished files to a "done" directory, do some scheduling so that it only downloads at full speed at night, and watch a certain directory for new .torrent files.
  6. Downloaded and configured pytvshows to download the .torrent files for TV shows that I was interested in, and added it to cron so it would download every hour from RSS, by calling:

    pytvshows -o/disk250/media/torrent/watch/
  7. Created a script named which would be run by cron every hour, so that it would make sure the copy of rtorrent was still alive. In the case it stopped working, the script cleans up after it and starts it up again:


    RTORRENTPS=$(ps ax | egrep ":[0-9]{2} rtorrent\$")

    [ -z "$RTORRENTPS" ] && {
    # start rtorrent
    rm -f /home/shalom/.rtorrent/rpc.socket /home/shalom/.rtorrent/session/*
    screen -dmS rtorrent sudo -u shalom rtorrent
    sleep 3 # to allow time for rtorrent to load and create the socket, before we change its permissions
    chmod ugo+w /home/shalom/.rtorrent/rpc.socket
    /etc/rc.d/init.d/lighttpd restart

Here's a copy of the ~/.rtorrent.rc that I used:

# Maximum number of simultanious uploads per torrent.
max_uploads = 4

# Global upload and download rate in KiB. "0" for unlimited.
download_rate = 0
upload_rate = 5

# Default directory to save the downloaded torrents.
directory = /disk250/media/torrent/inprogress/

# Move completed torrents to another directory
on_finished = move_complete,"d.set_directory=/disk250/media/torrent/done/ ; execute=mv,-u,$d.get_base_path=,/disk250/media/torrent/done/"

# Default session directory. Make sure you don't run multiple instance
# of rtorrent using the same session directory. Perhaps using a
# relative path?
session = /home/shalom/.rtorrent/session

# Watch a directory for new torrents, and stop those that have been
# deleted.
schedule = watch_directory,5,5,load_start=/disk250/media/torrent/watch/*.torrent
schedule = untied_directory,5,5,stop_untied=

# 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 0.1 with at least 2 MB uploaded, or else ratio 0.2
schedule = ratio,60,60,stop_on_ratio=1

# Port range to use for listening.
port_range = 6890-6999

# Enable XML-RPC access via a socket
scgi_local = /home/shalom/.rtorrent/rpc.socket

You can test the XML-RPC connection using the xmlrpc program to list all the RPC methods provided by the URL we set up:

/usr/sbin/xmlrpc system.listMethods

In the case of an error, you may get a response such as:

Failed.  Call failed.  HTTP response code is 500, not 200.  (XML-RPC fault code -504)

Check lighttpd's error logs for the reason for the 500 error-code. (The logs are located in /var/log/lighttpd/lighttpd.error.log according to the configuration above.)

In the case of success, you'll see a set of all the available commands:


Array of 385 items:
  Index  0 String: 'system.listMethods'
  Index  1 String: 'system.methodExist'
  Index  2 String: 'system.methodHelp'
  Index  3 String: 'system.methodSignature'
  Index  4 String: 'system.multicall'
  Index  5 String: 'system.shutdown'
  Index  6 String: 'system.capabilities'
  Index  7 String: 'and'
  Index  8 String: 'branch'
  Index  9 String: 'call_download'
  Index 10 String: 'cat'
  Index 11 String: 'close_low_diskspace'
  Index 12 String: 'close_on_ratio'
  Index 13 String: 'close_untied'
  Index 14 String: 'create_link'
  Index 15 String: 'd.check_hash'
  Index 16 String: 'd.close'
  Index 17 String: 'd.create_link'
  Index 18 String: 'd.delete_link'
  Index 19 String: 'd.delete_tied'
.... # snip several hundred lines
  Index 381 String: 'view_sort'
  Index 382 String: 'view_sort_current'
  Index 383 String: 'view_sort_new'
  Index 384 String: 'xmlrpc_dialect'
Last updated on 2009-06-28 12:14:06 -0700, by Shalom Craimer

Back to Tech Journal