Setup rtorrent + GNU Screen on Centos 6
Recently I found myself out running an errand across town. While running errands I decided that I wanted to download a large file (Centos DVD Images). Since these take a little while to download I thought 'Wouldn't it be great if I could tell my home server to download the torrents? They would probably be finished by the time I get home!'
This spurred me on to create a PHP based website that could be quickly and easily accessed from my mobile device. A key part of this system is having a BitTorrent client that can be scripted or in some other way manipulated to download a file then stop seeding when finished. Enter rtorrent. It appears to be the best fit for my purposes.
This article shows how to get rtorrent installed and configured on a Centos 6 x64 system
Notes:
- rTorrent
- The libTorrent and rTorrent Project [libtorrent.rakshasa.no]
- Installing libTorrent and rTorrent on Linux Centos [markus.revti.com]
- Compile rtorrent on Centos 64bit [lamnk.com]
- Howto: Use rtorrent like a pro [kmandla.wordpress.com]
- rTorrent dependencies
- libsigc++ [libsigc.sourceforge.net]
- libTorrent [libtorrent.rakshasa.no]
- pkg-config [freedesktop.org]
- GNU Screen
- GNU Screen [gnu.org]
- GNU Screen Quick Reference [aperiodic.net]
- Screen command with Bash Scripting [linuxquestions.org]
Install Pre-requisite software
- yum install gcc gcc-c++ curl curl-devel m4 automake perl openssl-devel libtool
- yum install ncurses ncurses-devel
- yum install screen
(used later on to keep a copy of rtorrent open in the background)
- yum install wget
(This isn't strictly required, but it does come in handy for downloading the packages!)
There are a few packages that we can't get through yum, so we'll install them manually. Throughout these steps I assume a Prefix-directory of /usr because I want my software going to /usr/bin, /usr/lib, etc...
- Install libsigc++
- Can be downloaded from their download page
- Run the following commands to Install (assumes that the file has been downloaded and decompressed)
- ./configure --prefix=/usr
- make
- sudo make install
Fairly straight-forward stuff
- Configure libsigc++ to be accessible & Usable by the libTorrent install (see further down). I ran the following pkg-config commands to make this work:
- updatedb
- locate pkgconfig | grep sigc++-2.0.pc
- Take the directory that was output by the grep command and use it to set the PKG_CONFIG_PATH environment variable:
export PKG_CONFIG_PATH=/usr/lib64/pkgconfig (this is the path from my system, YMMV) - Copy the sigc++-2.0.pc file from /usr/lib/pkgconfig to /usr/lib64/pkgconfig
- On my system this was necessary to get libtorrent to compile:
cp /usr/local/lib/pkgconfig/sigc++-2.0.pc /usr/lib64/pkgconfig/sigc++-2.0.pc
(YMMV)
- Install libtorrent
- Can be downloaded from their download site
- Decompress & run through the familiar make process:
- ./configure --prefix=/usr
- make
- sudo make install
- Configure libtorrent to be available when rTorrent is compiled. I ran the following pkg-config commands to make this work:
- updatedb
- locate pkgconfig | grep libtorrent.pc
- Take the directory that was output by the grep command and use it to set the PKG_CONFIG_PATH environment variable:
export PKG_CONFIG_PATH=/usr/lib64/pkgconfig (this is the path from my system, YMMV)
Note: exporting the PKG_CONFIG_PATH variable is redundand if you did this when installing libsigc++
- Copy the libtorrent.pc file from /usr/lib/pkgconfig to /usr/lib64/pkgconfig
- On my system this was necessary to get rtorrent to compile:
cp /usr/local/lib/pkgconfig/libtorrent.pc /usr/lib64/pkgconfig/libtorrent.pc
(YMMV)
Install & Configure rTorrent
If you have made it through the above process without any build errors you should be in good shape to compile rTorrent:
- rTorrent can be downloaded from the download page
- Decompress & run through the typical make process:
- ./configure --prefix=/usr
- make
- sudo make install
If all goes well you should be able to type which rtorrent and see a result
- Download the config file
- Place it in your user's home directory and rename it to .rtorrent.rc
- Edit the configuration file to your liking. It is well-commented, so it should be fairly straight forward to alter. For some 'help' you can see this blog post [kmandla.wordpress.com]
- I configured my profile to:
- Watch a certain folder for torrents and start downloading new ones as they appear
# Watch a directory for new torrents, and stop those that have been
# deleted.
schedule = watch_directory,5,5,load_start=/root/watch/*.torrent - Limit the uploading rate of the torrent client (since rtorrent needs to be on all the time)
# Global upload and download rate in KiB. "0" for unlimited.
#download_rate = 0
upload_rate = 50 - Limit how much the torrent client seeds (Primary purpose is download)
# 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,10,10,"stop_on_ratio=20,1M,10"
schedule = ratio,10,10,"stop_on_ratio=30,400M,600"
- Set a downloads folder where completed files should go
# Default directory to save the downloaded torrents.
directory = /shared/downloads
Run rTorrent
At this point rTorrent should be ready to run! I installed GNU Screen to allow me to start it and leave it running in the back-ground. From what I can tell, rTorrent doesn't run as a service. Maybe later on I'll take libTorrent and create a background-service torrent daemon. For now, screen quickly gets me where I want to go by typing these commands:
- screen (Starts a new terminal session in screen)
- rtorrent (starts rTorrent in the screen session
- Ctrl-a, d (Disconnects from the screen session while leaving rtorrent running)
Note: Press Ctrl-a then release the keys and press d to disconnect