Register for the iXsystems Community to get an ad-free experience and exclusive discounts in our eBay Store.

Install rutorrent in a jail

FlyingPersian

FreeNAS Experienced
Joined
Jan 27, 2014
Messages
201
Hi
I personally don't like transmission too much and I've also stumbled upon many people using rtorrent (rutorrent) as their client. Since I spent some time on installing it properly I decided to share my findings here with you guys.
First off, most of my knowledge can be credited to the user/admin wonslung on rutorrent forums. I mostly followd his tutorial with a few adjustments to make it work (you can find the tutorial here). Thus my tutorial will be very similar to his. So, let us begin:

1. First we start by creating a jail, I myself chose a pluginjail without any particular reason. Keep the standard settings, give it a proper name such as "rutorrent" or "rtorrent". Enter the standard gateway, let the rest be and press ok.

2. SSH into the jail and do the following:

Code:
portsnap fetch
portsnap extract
pkg update
pkg upgrade
cd /usr/ports/ports-mgmt/portmaster
make install clean
echo 'WITH_PKGNG=yes' >> /etc/make.conf
pkg2ng
portmaster -avB
<accept all of the defaults>


I know many people prefer pkgng, but I haven't tried that one out yet and I suppose that this will also do the job.

3. Then install rtorrent (I chose rtorrent)

Code:
 cd /usr/ports/net-p2p/rtorrent-devel
--or--
cd /usr/ports/net-p2p/rtorrent

make install clean


Leave all the settings to standard and press enter any time the blue settings window appears.

4. Next we will install a webserver, in our case apache.

Code:
 cd /usr/ports/www/apache22
make install clean
echo DEFAULT_VERSIONS=apache=2.2 >> /etc/make.conf


Again, default settings.

5. Then we'll install mod_scgi

Code:
 cd /usr/ports/www/mod_scgi
make install clean


6. Next php5. BUT this is where my problems started. Usually we're supposed to install php5 (the newest version I think), but the tutorial is a little older and it might have worked then, but not now. You have to select the Apache Module in the settings, but it won't be in php5. We have to install a slightly older version, but I don't know if there are any disadvantages such as security.

Code:
 cd /usr/ports/lang/php53
make install clean


Again, only check the Apache Module, the rest can stay default.

7. Next we have to install php53-extensions. I Do not know precisely which ones you need, but I've collected the information of multiple sites and it works fine for me:

Code:
 cd /usr/ports/lang/php53-extensions
make install clean


Check these to the already checked (some might be checked already)

Code:
BZ2,  CTYPE, CURL, DOM, FILEINFO, FILTER, GD, HASH, ICONV, JSON, MBSTRING, MBCRYPT, MYSQL, MYSQLI MHASH, OPENSSL, PCRE, PDO, PDO_SQLITE, POSIX, SESSION, SIMPLEXML, SOCKETS, SPL, SQLITE, TOLKENIZER, XML, XMLREADER, XMLRPC, XMLWRITER, ZIP


This takes up the longest time and you've to confirm many settings.

8. Next we copy over a php.ini file

Code:
cp /usr/local/etc/php.ini-production /usr/local/etc/php.ini


9. Next we have to enable php and mod_scgi in the Apache config. I use the standard text editor, you can choose whatever you like.

Code:
ee /usr/local/etc/apache22/httpd.conf


Find the modules section. There's a bunch of lines starting with LoadModule. Add this to the bottom:

Code:
 LoadModule scgi_module    libexec/apache22/mod_scgi.so
LoadModule php5_module        libexec/apache22/libphp5.so


Then search for "mime" (press ESC - - > search) and add this:

Code:
 AddType application/x-httpd-php .php
AddType application/x-httpd-php-source .phps


Save it.

10. Next we enable apache

Code:
 ee /etc/rc.conf
--add this--
apache22_enable="YES"
--save--


11. Then start apache

Code:
 /usr/local/etc/rc.d/apache22 start


It might give you some error regarding the server name, just ignore it, it doesn't do any harm

12. My source tutorial is written to support multiple users, so I'll just stick to it.

Code:
 mkdir -p /usr/local/www/rutorrent-users
cd /usr/local/www/rutorrent-users
mkdir USER1
cd USER1


You can of course name "rutorrent-users" whatever you like.
Name USER1 to whatever you want.

13. Then download and extract rutorrent.

Code:
 wget http://dl.bintray.com/novik65/generic/rutorrent-3.6.tar.gz
tar xfvz rutorrent-3.6.tar.gz
wget http://dl.bintray.com/novik65/generic/plugins-3.6.tar.gz
tar xfvz plugins-3.6.tar.gz
mv -r plugins/* rutorrent/plugins/
rmdir plugins


According to the tutorial you have to chmod 777 certain folders, but since the folder structure of rutorrent changed since the tutorial was written just chmod 777 the rutorrent folder.

Code:
chmod 777 rutorrent


Be aware that this might be insecure!

14. Next we install "screen" which we use to run rtorrent.

Code:
 cd /usr/ports/sysutils/screen
make install clean 


15. Every user needs his own account, so go ahead and create one for every user

Code:
 adduser
--set USER1 as the username--
--set the home dir to /USER1/--


Just create a random password. Do this for each user you have. Write down the password.

16. Next we create folders for rtorrent. You can put them wherever you like, but the user's folder makes sense.

Code:
 cd /home/USER1
mkdir -p rtorrent/download
mkdir -p rtorrent/.session
chown -R USER1:USER1 rtorrent/


17. Next we copy over and edit the .rtorrent.rc

Code:
 cp /usr/local/share/examples/rtorrent/rtorrent.rc /home/USER1/.rtorrent.rc
chmod 644 /home/USER1/.rtorrent.rc


Edit the file:

Code:
 ee .rtorrent.rc
--remove the hash tags in front of every setting you want to change. Most of the stuff should be clear. - -
--find "directory =" - -
directory = /USER1/rtorrent/download/
--find "session =" - -
session = USER1/rtorrent/.session/
--find "port_range =", "scgi_port =" and "dht_port=" - -

port_range = 50001-50001
dht_port = 25001
scgi_port = 127.0.0.1:5001


I've read that ports above 50.000 are common for the port range.
For the next user the last three lines would look like this:

Code:
 port_range = 50002-50002
dht_port = 25002
scgi_port = 127.0.0.1:5002


If you can't find any of the lines just add them at the bottom of the file.
Also add the following if you're using private sites:

Code:
dht=disable


18. Next we do some stuff with apache for authentication.

Code:
 mkdir -p /usr/local/www/private/
htpasswd -c /usr/local/www/private/.htpasswd USER1


Enter the password for USER1. If you do this for other users thereafter leave out the "-c":

Code:
htpasswd /usr/local/www/private/.htpasswd USER2


19. Next we create a group with the name of USER1 and USER1 as a member:

Code:
ee /usr/local/www/private/.htgroups
--enter this:--
USER1: USER1


20. Then we need alias' so that apache knows where the rutorrent files are.

Code:
ee /usr/local/etc/apache22/Includes/USER1.conf


It's important that you always name the right user, it doesn't always have to be USER1. I just don't want to write that all the time, but I assume that this is clear.

Enter this:

Code:
Alias /USER1 /usr/local/www/rutorrent-users/USER1/
<Directory /usr/local/www/rutorrent-users/USER1>
    Options Indexes FollowSymLinks
    AllowOverride AuthConfig
    Order allow,deny
    Allow from all
  </Directory>

SCGIMount /RPC1 127.0.0.1:5001
<Location /RPC1>
AuthName "Private"
AuthType Basic
AuthBasicProvider file
AuthUserFile /usr/local/www/private/.htpasswd
AuthGroupFile /usr/local/www/private/.htgroups
Require group USER1
</Location>


Here you have to replace the USER1 with your username AND you have to change the SCGIMount accordingly (USER1 --> RPC1, Port 5001, USER2 --> RPC2, Port 5002 etc)

Then restart apache

Code:
/usr/local/etc/rc.d/apache22 restart


Again, you might get some error with the server name, just disregard that.

21. The command to start rtorrent is this:

Code:
screen rtorrent


But I had some issues with the .rtorrent.rc some times cuz it didn't use the one in my /USER1/rtorrent folder. So I added this to the command:

Code:
screen rtorrent -n -o import=/USER1/.rtorrent.rc


Done :) The URL to reach your rutorrent is

Code:
http//IP.to.jail/USER1/rutorrent/


22.

Code:
ee /usr/local/www/rutorrent-users/USER1/rutorrent/conf/config.php

change
$scgi_port = 5000;
  to
$scgi_port = 5001;


Repeat this step for additional users

23. Fix unrar plugin

Code:
cd /usr/ports/archivers/unrar
make install clean



Have fun and enjoy. If you see any error or have any suggestions to make this even better, let me know.
 
Last edited:
Joined
Feb 19, 2015
Messages
15
Alright. Just finished running this close to 10 times before I hammered out all the bugs and missing steps. The original guide by wonslug on the rutorrent support forum helped a ton to identify them. Hopefully the OP can incorporate these into the instructions.

First, your FreeBSD jail won't be updated when you create it, so there's actions you must take that are assumed to have occurred before Step 1 above. While they may be obvious to somebody familiar with installing from ports, I'm used to pkg, dpkg, ipkg, apt, etc. so this was non-intuitive.

Additionally, rtorrent-devel is currently broken. When it notices you don't have libtorrent-devel installed, it attempts to install it. However, it fails because it doesn't see libtool. Installing libtool does not resolve this. I recommend sticking with rtorrent in the meantime.

Step 0.5
Code:
portsnap fetch
portsnap extract
pkg update
pkg upgrade
cd /usr/ports/ports-mgmt/portmaster
make install clean
echo 'WITH_PKGNG=yes' >> /etc/make.conf
pkg2ng
portmaster -avB
   <accept all of the defaults>


Step 3.
Code:
   add to end:
echo DEFAULT_VERSIONS=apache=2.2 >> /etc/make.conf


Step 7.
Code:
cp /usr/local/etc/php.ini-production/usr/local/etc/php.ini
   should be:
cp /usr/local/etc/php.ini-production /usr/local/etc/php.ini


Step 12.
Code:
   add to the end:
rmdir plugins


Step 16.
Code:
cp /usr/local/share/example/rtorrent-devel/rtorrent.rc /home/USER1/.rtorrent.rc
   should be
cp /usr/local/share/examples/rtorrent-devel/rtorrent.rc /home/USER1/.rtorrent.rc
   (or, in my case, not devel)


Code:
--find "porte_range =", "scgi_port =" and "dht_port=" - -
   should be
--find "port_range =", "scgi_port =" and "dht_port=" - -


Also, I would recommend adding this if you use private trackers:
Code:
dht=disable


Step 18.
Code:
USER1: User1
   should be (for clarity)
USER1: USER1


Step 19.
Code:
Alias /USER1/usr/local/www/rutorrent-users/USER1/
   should be (note the space)
Alias /USER1 /usr/local/www/rutorrent-users/USER1/


Code:
<Directory /usr/local/www/rtorrent-users/USER1>
   should be (note the "u")
<Directory /usr/local/www/rutorrent-users/USER1>


By the way... this resolves the rtorrent error you observed and the need to run rtorrent with "-n -o -import=/USER1/rtorrent.rc"

Step 20.
Add note: You should exit the root user before starting rtorrent! Might also want to tell people how to detach the session (Ctrl+A, then d) to return to the CLI.

Code:
http//IP.to.jail/USER1
   should be
http//IP.to.jail/USER1/rutorrent/


Step 21. (add me)
Code:
ee /usr/local/www/rutorrent-users/USER1/rutorrent/conf/config.php

   change
$scgi_port = 5000;
   to
$scgi_port = 5001;


Step 22. (add me)
Repeat Step 21 for additional users.

Step 23.
Fix unrar plugin:
Code:
cd /usr/ports/archivers/unrar
make install clean


I'm still battling a few plugin permissions and missing (common) plugins. As I hammer those out, I'll keep a log and post here once I have something substantial to add.
 

FlyingPersian

FreeNAS Experienced
Joined
Jan 27, 2014
Messages
201
Hi
Good to see you got it working. Unfortunately when I tried to reinstall this I got the exact same libtorrent issue you got, but not just on the developer version. I'll give it a shot with your steps and then edit my post.

Edit: Ok I tried everything and it worked fine. I'll due the editing tomorrow. As which user would you run rutorrent if not as root?
 
Last edited:
Joined
Feb 19, 2015
Messages
15
Edit: Ok I tried everything and it worked fine. I'll due the editing tomorrow. As which user would you run rutorrent if not as root?
You should be running rutorrent as USER1, USER2, etc.

Short 'n' sweet: If you run rtorrent as root and I breach your install, I now own your jail.
 

Whattteva

FreeNAS Experienced
Joined
Mar 5, 2013
Messages
729
What exactly is the advantage of rutorrent over transmission? I myself personally just use transmission cause I never have any problems with it and just don't see the point of using anything else (mostly out of laziness to try out other things).
 
Joined
Feb 19, 2015
Messages
15
What exactly is the advantage of rutorrent over transmission? I myself personally just use transmission cause I never have any problems with it and just don't see the point of using anything else (mostly out of laziness to try out other things).
That question has been hashed out many times over. Google will go more in depth, but for me personally, the short list would be...

autodl
channels
ratio groups
fast resume
mktorrent
scripted x-seeding
autotools
file manager
file share
unpack
geoip
mediastream
diskspace/cpuload
cookies
...and tons of tweakability with .rtorrent.rc.
 

Whattteva

FreeNAS Experienced
Joined
Mar 5, 2013
Messages
729
I did search google for rutorrent vs transmission and didn't really come up with anything conclusive other than very subjective forum posts and software insider (the most objective one), but even that is just a simple checklist comparison which actually ended up being Transmission having more checks (some useless comparisons too, like Gizmo and CNET ratings).

Anyways, looking at your feature list, it's clear why I never bothered. Basically, it's all features I don't use since my needs are pretty basic (either magnet link or torrent files in watch dir). Heck, I don't even use their web GUI feature since I only ever use the CLI client through SSH.
 
Joined
Feb 19, 2015
Messages
15
Transmission is a fine client, if all you want is the basics. The rutorrent plug in system allows for neatlt organized, fully customizable, automated setups when configured properly with other tools.

If you're happy with what you have, there's no real reason to switch.
 
Joined
Feb 19, 2015
Messages
15
Been testing my install that followed these steps. 1000 torrents loaded and still extremely responsive. Upload speeds are great.

.rtorrent.rc needs addition tweaks over what is recommended above for optimal performance. I moved over most of my settings from my little NAS, but it's clear transfer speeds aren't everything they could be. Namely, I have a lot more CPU/RAM to play with and my I/O is no longer CPU-limited. It follows that connection/transfer settings could use some tweaking.

There are some crucial add-ons that you'll be missing if you're used to a pre-configured seedbox from a reputable provoder. Once I get these added, configured, and tweaked, I'll post steps.

Out of the box, I'm getting approx 250 mb/s hashing, which is pretty similar to my raw I/O. This is on an e3-1231v3 with 32gb ECC and 4x 5tb 5400rpm WD Reds in a raidz1.

cpuload seems to be incorrectly reporting the load of only the 1st core. Will look into this. Hopefully I don't have to rebuild for threading.
 

FlyingPersian

FreeNAS Experienced
Joined
Jan 27, 2014
Messages
201
@Whattteva honestly I don't know why I switched to rtorrent back then, but for some reason I didn't like transmission :D

@Miller yes it also runs very smoothly over here. I just installed it with lighttpd yesterday and it works quite fine. I'm not sure how well it runs with many torrents. I'll write a tutorial about it soon.

Gesendet von meinem Nexus 4 mit Tapatalk 2
 
Joined
Feb 19, 2015
Messages
15
I just got to ~1800 torrents migrated (lots of hashing!) and rutorrent would fail to load. Scared me pretty good, except I could see rtorrent working fine in screen. It took a few minutes to realize that apache22 was quitting on me because it couldn't allocate enough memory. If you're running a large amount of torrents, you might notice rutorrent start to slow down as you approach the max memory limit.

The good news is two-fold:
  1. I had 1800 torrents loaded before I hit the default maximum (128 mb), so rutorrent is still very lightweight, especially compared to a properly specced FreeNAS box. On top of that, rtorrent is only 1-3% CPU usage on my e3-1231v3 with 12 active torrents with a constant 1 MB/s up speed (self-imposed rate limit).
  2. Increasing the maximum memory limit is very easy.

To do this, simply (as root):
Code:
ee /usr/local/etc/php.ini
   look for "memory_limit = 128M"
   change the value to whatever you like... I went 1024M because I have plenty of RAM
   save and exit
service apache22 restart


Don't forget to refresh rutorrent in your browser.
 

FlyingPersian

FreeNAS Experienced
Joined
Jan 27, 2014
Messages
201
Thanks, good to know. I personally don't need it, I don't have that many in my client :D More like 100 max :x
 
Joined
Feb 19, 2015
Messages
15
Understood. Just documenting here, since it's one of the two applicable results that come up in Google searches.
 

FlyingPersian

FreeNAS Experienced
Joined
Jan 27, 2014
Messages
201
Yeah that's cool, the more the better :)
 

FlyingPersian

FreeNAS Experienced
Joined
Jan 27, 2014
Messages
201
Here is my new tutorial. I hope it'll be moved to the How-To section.
 

FlyingPersian

FreeNAS Experienced
Joined
Jan 27, 2014
Messages
201
I figured out how to get rtorrent to start at boot. I'm using a small script I wrote + crontab.

1. Create a script, I decided to put it into the home dir of the user running rutorrent

Code:
cd /home/admin/
nano rtorrent.sh

--Paste these line and save it and exit--

#!/bin/sh
PATH=/etc:/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin

#run rtorrent
/usr/local/bin/screen -d -m -S rtorrent /usr/local/bin/rtorrent


2. Change owner and make it executeable

Code:
chmod +x rtorrent.sh
chown user:user rtorrent.sh


3. "su" allows you to work as a certain user in a jail. We do this to edit the user's crontab.

Code:
su admin

--I hate the editor vi, which is used to edit crontab, so I'll change the editor it's opened with. Keep in mind that this setting will be resetted once you leave the editor--

export EDITOR=/usr/local/bin/nano

crontab -e

--Paste these lines, then save it and exit--

SHELL=/bin/sh
PATH=/etc:/bin:/sbin:/usr/bin:/usr/sbin

#start rtorrent
@reboot /home/user/rtorrent.sh


4. Exit the jail and restart it via the WebGUI. rtorrent should be running.

I first had issues with rtorrent not being able to access all the binary files, but I fixed that by adding the appropriate PATH to the script.
Let me know if you run into any issues.
 
Last edited:
Joined
Aug 22, 2015
Messages
2
I'm having issues with php part keep getting:
Code:
httpd: Syntax error on line 109 of /usr/local/etc/apache22/httpd.conf: Cannot load /usr/local/libexec/apache22/libphp5.so into server: Cannot open "/usr/local/libexec/apache22/libphp5.so"


php5
 

ondjultomte

FreeNAS Experienced
Joined
Aug 10, 2015
Messages
106
Hi! I'm trying to get rtorrent in a jail but make install clean doesnt work

root@rtorrent:/usr/ports/ports-mgmt/portmaster # cd /usr/ports/ports-mgmt/portmaster/
root@rtorrent:/usr/ports/ports-mgmt/portmaster # make install clean
===> portmaster-3.17.8_1 pkg(8) must be version 1.6.0 or greater, but you
have 1.2.7_2. You must upgrade the ports-mgmt/pkg port first.
*** [install] Error code 1


I just did the upgrade

root@rtorrent:/usr/ports/ports-mgmt/portmaster # pkg upgrade
Updating repository catalogue
Nothing to do
 

FlyingPersian

FreeNAS Experienced
Joined
Jan 27, 2014
Messages
201
Either do :

Code:
pkg update
pkg upgrade


OR

Code:
cd /usr/ports/ports-mgmt/pkg
make install clean
 

ondjultomte

FreeNAS Experienced
Joined
Aug 10, 2015
Messages
106
Hi! I'm trying to get rtorrent in a jail but make install clean doesnt work

root@rtorrent:/usr/ports/ports-mgmt/portmaster # cd /usr/ports/ports-mgmt/portmaster/
root@rtorrent:/usr/ports/ports-mgmt/portmaster # make install clean
===> portmaster-3.17.8_1 pkg(8) must be version 1.6.0 or greater, but you
have 1.2.7_2. You must upgrade the ports-mgmt/pkg port first.
*** [install] Error code 1


I just did the upgrade

root@rtorrent:/usr/ports/ports-mgmt/portmaster # pkg upgrade
Updating repository catalogue
Nothing to do
cd /usr/ports/ports-mgmt/pkg

and do a

make install
make deinstall
make reinstall


solved it
 
Top