I’ve been using one of my PI’s as a torrent server for some time. Recently I decided to refresh the entire system. This will NOT go into the legalities of downloading anything, I expect everyone to only be using this for downloading raspberry images 🙂
Version Info:
2014-01-07-wheezy-raspbian.img
libtorrent 0.13.2
rtorrent 0.9.2
rutorrent 3.6
I’m going to assume you can SSH to your PI, and recommend you get all the latest updates before you start. I’m also going to be naughty and be running all the commands as root.
sudo su –
Then we’ll get the stuff needed to compile rtorrent and a few things needed for the plugins
apt-get install subversion build-essential automake libtool libcppunit-dev libcurl3-dev libsigc++-2.0-dev libxmlrpc-c-dev unzip unrar-free curl libncurses-dev apache2 php5 php5-cli php5-curl libapache2-mod-scgi mediainfo ffmpeg screen
While your waiting may as well get a coffee. With that all finished we’re going to grab the rtorrent packages.
mkdir /root/rtorrent
cd /root/rtorrent
wget http://libtorrent.rakshasa.no/downloads/libtorrent-0.13.2.tar.gz
wget http://libtorrent.rakshasa.no/downloads/rtorrent-0.9.2.tar.gz
wget http://dl.bintray.com/novik65/generic/rutorrent-3.6.tar.gz
wget http://dl.bintray.com/novik65/generic/plugins-3.6.tar.gz
tar xvf libtorrent-0.13.2.tar.gz
tar xvf rtorrent-0.9.2.tar.gz
tar xvf rutorrent-3.6.tar.gz
tar xvf plugins-3.6.tar.gz
Now that you’ve got everything extracted it’s time to compile and install libtorrent
cd /root/rtorrent/libtorrent-0.13.2
./autogen.sh
./configure
make
make install
With libtorrent installed it’s time to compile and install rtorrent
cd /root/rtorrent/rtorrent-0.9.2
./autogen.sh
./configure --with-xmlrpc-c
make
make install
ldconfig
Once you’ve reached this bit, we’re finished with the hanging around. We’ll now install rutorrent and it’s plugins
cd /root/rtorrent
rm /var/www/index.html
cp -r rutorrent/* /var/www/
cp -r plugins/* /var/www/plugins
chown -R www-data:www-data /var/www
a2enmod scgi
service apache2 restart
We’ll next create a new user account for rtorrent to run as
adduser -m -r rtorrent
Now we switch to the new user account to add the required rtorrent directories and config
su rtorrent
mkdir .sessions
mkdir complete
mkdir torrents
mkdir watch
nano -w .rtorrent.rc
Copy and Paste the following:-
# 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 = 15
# Global upload and download rate in KiB. "0" for unlimited.
download_rate = 0
upload_rate = 100
# Default directory to save the downloaded torrents.
directory = ~/torrents
# Default session directory. Make sure you don't run multiple instance
# of rtorrent using the same session directory. Perhaps using a
# relative path?
session = ~/.sessions
# Watch a directory for new torrents, and stop those that have been
# deleted.
schedule = watch_directory,5,5,load_start=~/watch/*.torrent
schedule = untied_directory,5,5,stop_untied=~/watch/*.torrent
# Close torrents when diskspace is low.
schedule = low_diskspace,5,10,close_low_diskspace=200M
# 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"
#schedule = ratio,5,5,"stop_on_ratio=1,1M,10"
ratio.enable=
ratio.min.set=1
ratio.max.set=2
ratio.upload.set=1K
system.method.set = group.seeding.ratio.command, d.close=, d.stop=
# Set Schedules
#schedule = throttle_1,00:10:00,24:00:00,download_rate=0
#schedule = throttle_2,07:50:00,24:00:00,download_rate=200
# Stop Seeding When complete
#system.method.set_key = event.download.finished,1close_seeding,d.close=
#system.method.set_key = event.download.finished,2stop_seeding,d.stop=
# 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 = 51515-51520
# 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
#encryption = allow_incomming,try_outgoing
# 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
dht = off
# UDP port to use for DHT.
#
# dht_port = 6881
# Enable peer exchange (for torrents not marked private)
#
# peer_exchange = yes
peer_exchange = no
#
# 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
#Added for rutorrent stuff
encoding_list = UTF-8
#scgi_local = /tmp/rpc.socket
#schedule = chmod,0,0,"execute=chmod,777,/tmp/rpc.socket"
scgi_port = localhost:5000
# Start The Plugins when Rtorrent Starts not when the page is first opened. If apache service is restart separately the plugins are likely to be stopped. Only really needed for RSS feeds.
execute = {sh,-c,/usr/bin/php /var/www/php/initplugins.php &}
Save and Exit (ctrl+x then y then enter)
We now need to perform a test run of rtorrent.
rtorrent
It should start without any problems. You may get a few warnings inside rtorrent, but it should still be running. To Exit press ctrl+q.
You should now exit the rtorrent user.
exit
Finally we’re going to setup rtorrent to automatically start when the PI is powered up.
nano -w /etc/init.d/rtorrent
Copy and Paste the Following:-
#!/bin/bash
# To start the script automatically at bootup type the following command
# update-rc.d torrent defaults 99
RTUSER=rtorrent
TORRENT=/usr/local/bin/rtorrent
case $1 in
start)
#display to user that what is being started
echo "Starting rtorrent..."
sleep 4
#start the process and record record it's pid
rm /home/rtorrent/.sessions/rtorrent.lock
start-stop-daemon --start --background --pidfile /var/run/rtorrent.pid --make-pidfile --exec /bin/su -- -c "/usr/bin/screen -dmUS torrent $TORRENT" $RTUSER
## start-stop-daemon --start --background --exec /usr/bin/screen -- -dmUS torrent $TORRENT
#output failure or success
#info on how to interact with the torrent
echo "To interact with the torrent client, you will need to reattach the screen session with following command"
echo "screen -r torrent"
if [[ $? -eq 0 ]]; then
echo "The process started successfully"
else
echo "The process failed to start"
fi
;;
stop)
#display that we are stopping the process
echo "Stopping rtorrent"
#stop the process using pid from start()
start-stop-daemon --stop --name rtorrent
#output success or failure
if [[ $? -eq 0 ]]; then
echo "The process stopped successfully"
else
echo "The process failed to stop"
fi
;;
*)
# show the options
echo "Usage: {start|stop}"
;;
esac
Save and Exit (ctrl+x then y then enter)
Then run
chmod +x /etc/init.d/rtorrent
update-rc.d rtorrent defaults
And that’s it. You could now start rtorrent using “/etc/init.d/rtorrent start”, but it’s just as easy to reboot and test that the startup scripts runs. Once you’ve reboot or started rtorrent you can access the webpage at http://{ip-address or name} Notes:-
This setup is meant to run internally, as such there is no security on the apache setup.
Personally I forward ports 51515-51520 on the router onto the PI, this makes a difference in download speed (much quicker) but as it's opening ports it's a security risk so you'll have to decided whether or not to.
I run this setup behind a vpn using ipredator.se, if there's any demand I'll write up another guide on how to configure that and ensure your traffic is locked to only go over the vpn.
Thanks for the great tutorial. I was using deluge up until tonight, and then i got fed up with having to restart the daemon manually after it crashes, and every proposed solution does not work.
I want to use this tutorial, as all my peers say that rTorrent is the best torrent downloader for a RPi, however me (not experienced in Linux whatsoever) would still like to have the torrents download in one directory, and then be moved to another once finished, similarly like one could do using Deluge, and because I do not want the two 32GB flash drives I acquired to go to waste.
Could you please point out how one could possibly achieve this?
Hi Eugene,
There is a function within rutorrent to automatically move complete files. Go into Settings, and look for the autotools option. Tock the option ‘Enable AutoMove feature and give it the location you want the files moved to and operation type Move.
I use this feature to move everything into a complete folder ready for me to sort out. If you have USB drives auto mounted you could use a path they are mounted to. but I’d be careful unplugging them while something is in the middle of moving could be bad.
Another thing to note is the path HAS to be writable by the rtorrent user. This is also part of the reason I use a complete folder under the rtorrent user.
Another thing I use (but way outside the scope of this) is a script (executed by cron fr the rtorrent user) to move everything from the complete folder out to a server. with a bit of tweaking you could do something similar to first check if a usb drive is present then 2) mount it 3) move each of the complete files from the complete folder to the usb 4) umount the usb. If you had that run every hour you could more or less remove the usb safely taking your new files. and while there’s no usb drive insert the files just buildup into the complete folder ready to copy.
If you’d like to see the script I use for the network stuff let me know and I’ll put it on here.
Nice guide! I will probably try this but i want to use autodl-irssi to monitor some IRC-channels in rutorrent. It is included in this guide? If not, how to install it?
Thanks,
autodl-irssi isn't something I've used, but a quick look at the rutorrent page does have some install instructions, not sure how well these will work in this setup though, may have some dependencies that will need resolving as you install, but worth a go. I'd backup your SD card before running through the install though so you have something to fall back on.
Tried to do this now a few months later but some of the links are broken and some of the commands are failing.
Been a windows person and not knowing alot about linux type systems, that is very frustrating.
🙂 a few months ago I stopped using this setup and haven't needed to pull together up to date information.
I've just tried the libtorrent.rakshasa.no links and they do appear to be down. Not sure if this is a temporary thing, but there is a github page https://github.com/rakshasa where you can download a zip of rtorrent and libtorrent. you'd then have to use unzip instead of tar to extract these 2.
I'm unsure though if this is the stable/development branch I'll have to look into it tomorrow.