Skip to content

Instantly share code, notes, and snippets.

@rubenhortas
Last active December 21, 2025 13:57
Show Gist options
  • Select an option

  • Save rubenhortas/8e0d4285694e537c55efe60eba5af5f3 to your computer and use it in GitHub Desktop.

Select an option

Save rubenhortas/8e0d4285694e537c55efe60eba5af5f3 to your computer and use it in GitHub Desktop.
Optimized rTorrent configuration template with automated directory provisioning, disk space monitoring, ratio control (for public and private trackers) and handling of .torrent and [in]complete downloaded files
# Optimized rTorrent configuration template with automated directory provisioning,
# disk space monitoring, ratio control (for public and private trackers)
# and handling of .torrent and [in]complete downloaded files.
#
# Automations:
#
# - Disk management
#
# - Create instance directories
# - Set restrictive file permissions
# - Disable logging
# - Stop torrents if free disk space falls below 1000MB
#
# - Download management
#
# - Create custom views and ratios:
# - Public trackers
# - Private trackers
# - Unlimited (seeding)
#
# - Watch Directories
# Any .torrent file placed in these directories will be automatically added to rTorrent
# in its corresponding category (public, private, unlimited), the ratios for the category will be applied,
# and the download will begin.
#
# - Delete files when canceling an incomplete download
#
# - Move files to their respective directories
# Instance layout (base paths)
method.insert=cfg.home,private|const|string,"/home/rubenhortas/"
method.insert=cfg.downloads,private|const|string,(cat,(cfg.home),"downloads/")
method.insert=cfg.basedir,private|const|string,(cat,(cfg.downloads),".rtorrent/")
method.insert=cfg.downloading,private|const|string,(cat,(cfg.basedir),"downloading/")
method.insert=cfg.session,private|const|string,(cat,(cfg.basedir),"session/")
method.insert=cfg.watch,private|const|string,(cat,(cfg.basedir),"torrents/")
method.insert=cfg.public,private|const|string,(cat,(cfg.watch),"public/")
method.insert=cfg.private,private|const|string,(cat,(cfg.watch),"private/")
method.insert=cfg.unlimited,private|const|string,(cat,(cfg.watch),"unlimited/")
method.insert=cfg.seeding,private|const|string,(cat,(cfg.basedir),"seeding/")
# Create instance directories
execute.throw=sh,-c,(cat,\
"mkdir -p \"",(cfg.basedir),"\" ",\
"\"",(cfg.downloading),"\" ",\
"\"",(cfg.session),"\" ",\
"\"",(cfg.watch),"\" ",\
"\"",(cfg.public),"\" ",\
"\"",(cfg.private),"\" ",\
"\"",(cfg.unlimited),"\" ",\
"\"",(cfg.downloads),"\" ",\
"\"",(cfg.seeding),"\" ")
# Listening port for incoming peer traffic
network.port_range.set=1234-1234
network.port_random.set=no
# Tracker-less torrent and UDP tracker support
# (Conservative settings for 'private' trackers; adjust for 'public' trackers)
dht.mode.set=auto
dht.port.set=1235
protocol.pex.set=1
## Adding public DHT servers for easy bootstrapping
schedule2=dht_node_1,5,0,"dht.add_node=router.utorrent.com:6881"
schedule2=dht_node_2,5,0,"dht.add_node=dht.transmissionbt.com:6881"
schedule2=dht_node_3,5,0,"dht.add_node=router.bitcomet.com:6881"
schedule2=dht_node_4,5,0,"dht.add_node=dht.aelitis.com:6881"
# Peer settings
## Set whether the client should try to connect to UDP trackers
trackers.use_udp.set=yes
## Maximum number of simultaneous upload slots
throttle.max_uploads.set=800
throttle.max_uploads.global.set=800
## Maximum and minimum number of peers to connect to per torrent during download
throttle.min_peers.normal.set=1
throttle.max_peers.normal.set=200
## Maximum and minimum number of peers to connect to per torrent while seeding
# '0' for same as downloading
throttle.min_peers.seed.set=1
throttle.max_peers.seed.set=100
# Set the numwant field sent to the tracker, which indicates how many peers we want
# A negative value disables this feature
trackers.numwant.set=-1
# Protocol encryption
protocol.encryption.set=allow_incoming,try_outgoing,enable_retry
## Maximum number of simultaneous HTTP request (used by announce or scrape requests)
network.http.max_open.set=75
# Limits for file handle resources, this is optimized for
# an `ulimit` of 1024 (a common default). You MUST leave
# a ceiling of handles reserved for rTorrent's internal needs!
# (you have to modify the system wide settings with ulimit!)
## Maximum number of open files rtorrent can keep open
network.max_open_files.set=500
## Maximum number of connections rtorrent can accept/make (sockets)
network.max_open_sockets.set=500
# Memory resource usage (increase if you have a large number of items loaded
# and/or the available resources to spend)
# Set the max amount of memory address space used to mapping file chunks.
# This refers to memory mapping, not physical memory allocation.
pieces.memory.max.set=3072M
# Max packet size using xmlrpc
network.xmlrpc.size_limit.set=4M
# Basic operational settings (no need to change these)
session.path.set=(cfg.session)
directory.default.set=(cfg.downloading)
# log.execute=(cat,(cfg.logs),"execute.log")
# log.xmlrpc=(cat,(cfg.logs),"xmlrpc.log")
# execute.nothrow=sh,-c,(cat,"echo >",(session.path),"rtorrent.pid"," ",(system.pid))
# Other operational settings
encoding.add=UTF-8
system.umask.set=0077
system.cwd.set=(directory.default)
network.http.dns_cache_timeout.set=25
schedule2=monitor_diskspace,15,60,((close_low_diskspace,1000M))
# view.sort_current=seeding,greater=d.ratio=
# keys.layout.set=qwerty
# network.http.capath.set="/etc/ssl/certs"
## Maximum number of simultaneously active downloads (torrents being downloaded)
# throttle.max_downloads.global.set=1
## Maximum number of simultaneously active torrents (downloading + seeding)
## For example, if you want to download 1 at a time, and seed up to 4 others.
# throttle.max_active.global.set=5
# curl options to add support for nonofficial SSL trackers and peers
# network.http.ssl_verify_peer.set=0
# network.http.ssl_verify_host.set=0
# Check hash for finished torrents
pieces.hash.on_completion.set=no
# Some additional values and commands
method.insert=system.startup_time,value|const,(system.time)
method.insert=d.data_path,simple,\
"if=(d.is_multi_file),\
(cat,(d.directory),/),\
(cat,(d.directory),/,(d.name))"
method.insert=d.session_file,simple,"cat=(session.path),(d.hash),.torrent"
# Run the rTorrent process as a daemon in the background
# (and control via XMLRPC sockets)
# system.daemon.set=true
# network.scgi.open_local=(cat,(session.path),rpc.socket)
# execute.nothrow=chmod,700,(cat,(session.path),rpc.socket)
# Logging:
# Levels=critical error warn notice info debug
# Groups=connection_* dht_* peer_* rpc_* storage_* thread_* tracker_* torrent_*
# print=(cat,"Logging to ",(cfg.logfile))
# log.open_file="log",(cfg.logfile)
# log.add_output="info","log"
# log.add_output="tracker_debug","log"
# Custom views and ratios
## Main
view.sort_current=main,less=d.timestamp.started=
view.sort_new=main,greater=d.timestamp.started=
view.sort=main
## Public trackers
view.add=view_public
view.persistent=view_public
view.sort_current=view_public,less=d.timestamp.started=
view.sort_new=view_public,greater=d.timestamp.started=
view.sort=view_public
group.insert=public,view_public
group.public.ratio.enable=
group.public.ratio.max.set=200
method.set=group.public.ratio.command,d.close=
## Private trackers
view.add=view_private
view.persistent=view_private
view.sort_current=view_private,less=d.timestamp.started=
view.sort_new=view_private,greater=d.timestamp.started=
view.sort=view_private
group.insert=private,view_private
group.private.ratio.enable=
### Upload to a minimum ratio of 1.7
group.private.ratio.min.set=170
### Upload to a maximum ratio of 7
group.private.ratio.max.set=7000
### Upload a minimum of 25 MB
group.private.ratio.upload.set=25M
method.set=group.private.ratio.command,d.close=
## Seeding unlimited
view.add=view_unlimited
view.persistent=view_unlimited
view.sort_current=view_unlimited,less=d.timestamp.started=
view.sort_new=view_unlimited,greater=d.timestamp.started=
view.sort=view_unlimited
group.insert=unlimited,view_unlimited
group.unlimited.ratio.enable=
group.unlimited.ratio.max.set=0
## Custom throttles
# Global throttles to start
throttle.global_down.max_rate.set=0
throttle.global_up.max_rate.set=10000K
### Public trackers
throttle.up=public,10000K
throttle.down=public,0
### Private trackers
throttle.up=private,0
throttle.down=private,0
### Seeding unlimited
throttle.up=unlimited,0
throttle.down=unlimited,0
# Global rates per hours
# schedule2=night_download,01:00:00,07:30:00,download_rate=0
# schedule2=night_upload,01:00:00,07:30:00,upload_rate=0
# schedule2=day_download,07:30:00,01:00:00,download_rate=0
# schedule2=day_upload,07:30:00,01:00:00,upload_rate=10000K
# Watch directories
# custom1: Directory where the finished torrents will be moved
# custom2: 1=torrent, null=magnet link
# custom3: 1=stop when finished, null=pause when finished
method.insert=load_public,simple|private,\
"load.start=(argument.0),\
d.custom1.set=(cfg.downloads),\
d.custom2.set=1,\
d.custom3.set=1,\
d.throttle_name.set=public,\
view.set_visible=view_public"
directory.watch.added=(cfg.public),"load_public"
method.insert=load_private,simple|private,\
"load.start=(argument.0),\
d.custom1.set=(cfg.seeding),\
d.custom2.set=1,\
d.throttle_name.set=private,\
view.set_visible=view_private"
directory.watch.added=(cfg.private),"load_private"
method.insert=load_unlimited,simple|private,\
"load.start=(argument.0),\
d.custom1.set=(cfg.seeding),\
d.custom2.set=1,\
d.throttle_name.set=unlimited,\
view.set_visible=view_unlimited"
directory.watch.added=(cfg.unlimited),"load_unlimited"
# Handle magnet links as public torrents
method.insert=configure_magnet_link,simple|private,\
"d.custom1.set=(cfg.downloads);\
d.custom3.set=1;\
d.throttle_name.set=public"
method.insert=rm_file,simple|private,"execute={rm,-rf,--,(argument.0)}"
method.insert=d.move_to_complete,simple,"d.directory.set=$argument.1=;execute=mkdir,-p,$argument.1=;execute=mv,-u,$argument.0=,$argument.1="
# Log to a custom file for debugging
# method.insert=log_debug,simple|private,"execute={sh,-c,echo value $0 >> /tmp/rtorrent.log,(argument.0)}"
# Events
# Log the variable values for debugging: execute={sh,-c,echo inserted base_path $0 >> /tmp/rtorrent.log,(d.custom1)}
method.set_key=event.download.inserted_new, setup_main, "d.delete_tied=; branch=((not,((d.custom2)))),((configure_magnet_link))"
method.set_key=event.download.finished,move_finished,\
"d.move_to_complete=$d.base_path=,$d.custom1=;\
branch=((d.custom3)),((d.stop)),((d.pause));\
d.save_full_session="
method.set_key=event.download.erased, cleanup_all, "d.tied_to.set=; branch=((d.incomplete)),((rm_file,(d.base_path)))"
# Disable session locking
session.use_lock.set=no
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment