Skip to content

Setting upp Rtorrent, ruTorrent and autodl irssi

Mattias Martikainen edited this page Apr 27, 2018 · 3 revisions

Install new Ubuntu 17.04 server

Ugrade with the latest updates

$ sudo apt-get update && sudo apt-get dist-upgrade --yes Reboot the server

Install CIFS utilities

https://wiki.ubuntu.com/MountWindowsSharesPermanently

$ sudo apt-get install cifs-utils --yes

Create the directory where you want to mount the share

$ sudo mkdir /home/pi/share

Edit your fstab

$ sudo nano /etc/fstab

add the information of your share

//192.168.1.20/NAS /home/pi/share cifs uid=1000,credentials=/home/pi/.smbcredentials,iocharset=utf8,sec=ntlm 0 0

Add the .smbcredentials files

$ sudo nano /home/pi/.smbcredentials

with username and password, (without the "")

username="username" password="password"

Mount the share

$ sudo mount -a

Verify that you can see your files

$ cd /home/pi/share $dir

VPN

I'm using ovpn service, guides are located here, https://www.ovpn.com//sv/guides/ubuntu-cli

RTORRENT + LIBTORRENT + XML-RPC

$ sudo apt-get install -y build-essential subversion autoconf screen g++ gcc ntp curl comerr-dev pkg-config cfv libtool libssl-dev libncurses5-dev ncurses-term libsigc++-2.0-dev libcppunit-dev libcurl3 libcurl4-openssl-dev git

Install XML-RPC

XML-RPC is required for communication between rTorrent and ruTorrent.

enter these lines one by one $ svn co -q https://svn.code.sf.net/p/xmlrpc-c/code/stable /tmp/xmlrpc-c $ cd /tmp/xmlrpc-c $ ./configure --disable-libwww-client --disable-wininet-client --disable-abyss-server --disable-cgi-server $ make -j2 $ sudo make install

Each of these commands should be executed individually. (Don't copy and paste the entire block; input them line by line.) In the commands above we've...

  • downloaded and unpacked XML-RPC into its own temporary directory.
  • configured XML-RPC while disabling features that we don't need for rtorrent/rutorrent.
  • used the -j2 modifier for make, forcing it to recompile using two threads. If you have a dual- or quad-core CPU, you can increase this number to speed up the compiling process (to a degree).

Install LibTorrent

LibTorrent is the library on which the rTorrent client runs.

Before beginning this section, navigate to http://rakshasa.github.io/rtorrent/ in your browser to find the latest version of the library. Update the filename in the commands below to account for the version of LibTorrent you'd like to use. Make sure any communities you belong to have the torrent client you choose to use whitelisted.

$ cd /tmp $ curl http://rtorrent.net/downloads/libtorrent-0.13.6.tar.gz | tar xz $ cd libtorrent-0.13.6 $ ./autogen.sh $ ./configure $ make -j2 $ sudo make install

Install rTorrent

Just as with the previous section, navigate to http://rakshasa.github.io/rtorrent/ in your browser to find the latest version of the client. Update the filename in the commands below to account for the version of rTorrent you'd like to use. Make sure any communities you belong to have the torrent client you choose to use whitelisted.

$ cd /tmp $ curl http://rtorrent.net/downloads/rtorrent-0.9.6.tar.gz | tar xz $ cd rtorrent-0.9.6/ $ ./autogen.sh $ ./configure --with-xmlrpc-c $ make -j2 $ sudo make install $ sudo ldconfig

Make rTorrent directories and change their owner:

$ sudo mkdir -p /home/downloads/{.session,~watch} $ sudo chown -R pi:pi /home/downloads

Configure rTorrent

To configure rTorrent, you need to modify the file ~/.rtorrent.rc. You can either modify each line individually, or paste the preconfigured file provided below.

Create the file in your home directory:

$ nano ~/.rtorrent.rc

Paste the contents of following file into the .rtorrent.rc file you just created in Nano.

# 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 = 25
max_peers_seed = 60

# Maximum number of simultaneous uploads per torrent.
max_uploads = 30

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

# Default directory to save the downloaded torrents.
directory = /home/pi/share

# 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/downloads/.session

# Watch a directory for new torrents, and stop those that have been
# deleted.
schedule = watch_directory,5,5,load_start=/home/pi/share/~watch/*.torrent

# Close torrents when diskspace is low.
schedule = low_diskspace,5,60,close_low_diskspace=10240M

# 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 = 59113-59113

# 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 = yes

# Set whether 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

# 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 = disable

# UDP port to use for DHT.
#
# dht_port = 6881

# Enable peer exchange (for torrents not marked private)
#
peer_exchange = no

scgi_port = 127.0.0.1:5000

Modify these values as you see fit. Of note, these lines...

Define the default downloads directory as /home/downloads.

  • Tell rTorrent where to 'watch' for new torrent files that are uploaded to the server, and to not add them if there is less than 10GB of disk space available.
  • Disable DHT and peer exchange, which is a requirement of most private trackers.
  • Define the scgi port for rTorrent

Let's check to make sure rTorrent starts.

$ rtorrent

You won't see anything interesting; if it opens, we're good to go. Close rTorrent by pressing Ctrl+Q.

Next, we'll start rTorrent in a screen session that will allow it to continue running in the background.

$ screen -S rtorrent -fa -d -m rtorrent

What do those modifiers mean?

  • -S rtorrent Screen session name: rtorrent
  • -d -m Start screen in detached mode; exit if session terminates
  • -fa Flow control: automatic

Automatically Start rTorrent on System Boot

It's inconvenient to have to start rTorrent manually every time the server restarts. We can make it start automatically upon reboot by using a bash script.

create a new systemd service

$ sudo nano /etc/systemd/system/rtorrent.service

paste the following code in the terminal

` [Unit] Description=rtorrent Service After=network.target

[Service] Type=forking User=pi ExecStart=/usr/bin/screen -dmS rtorrent rtorrent ExecStop=/usr/bin/screen -S rtorrent -X quit

[Install] WantedBy=multi-user.target`

execute the following commands one by one

$ sudo systemctl enable rtorrent.service $ sudo systemctl start rtorrent.service

APACHE + PHP + SSL

Install Web Server Dependencies

For Ubuntu 16.4 LTS:

$ sudo apt-get install apache2 apache2-utils libapache2-mod-php

Configure Apache

Enable auth_digest module for ruTorrent authentication, SSL, and reqtimeout.

$ sudo a2enmod auth_digest ssl reqtimeout

Open apache2.conf

$ sudo nano /etc/apache2/apache2.conf

Edit this line

$ Timeout 300

with

$ Timeout 30

and add theese lines at the bottom

$ ServerSignature Off $ ServerTokens Prod

ServerTokens Prod will prevent Apache from reporting its version number, and ServerSignature Off will disable the server signature displayed in Apache error messages. Small steps to harden your system.

Restart Apache

$ systemctl restart apache2

Now, let's confirm that Apache and PHP are working.

$ echo '<?php phpinfo(); ?>' | sudo tee /var/www/html/info.php

The previous command created a file called info.php in the web root containing the function phpinfo(), which, if everything is functioning properly, should print a large table of information detailing your server's PHP settings.

Open your browser and navigate to 192.168.1.92/info.php

After confirming that PHP and Apache are working, remove info.php to avoid unnecessarily exposing information about your system.

$ sudo rm /var/www/html/info.php

Create an SSL Certificate

We'll create a self-signed SSL certificate that will allow you to access ruTorrent via the https:// protocol and will expire in 10 years.

$ sudo mkdir /etc/apache2/ssl $ sudo openssl req -x509 -nodes -days 3650 -newkey rsa:2048 -keyout /etc/apache2/ssl/apache.pem -out /etc/apache2/ssl/apache.pem

Enter the information

  • Country Name (2 letter code) [AU]:
  • State or Province Name (full name) [Some-State]:
  • Locality Name (eg, city) []:
  • Organization Name (eg, company) [Internet Widgits Pty Ltd]:
  • Organizational Unit Name (eg, section) []:
  • Common Name (e.g. server FQDN or YOUR name) []:
  • Email Address []:

Fill in the fields as prompted, or leave them blank (excepting the CN field). Be sure to input something for the CN (Common Name) field. Typically this is your server's hostname, but if you have a domain pointed to your server, you may use that instead.

Now, change the permissions for the newly created certificate, as some programs will refuse to load these certificates if permissions are set wrong.

$ sudo chmod 600 /etc/apache2/ssl/apache.pem

Configure Apache Access

Open Apache's default configuration:

$ sudo nano /etc/apache2/sites-available/default

Modify as follows, or replace the whole document, to enable SSL on port 443 and to setup Auth Digest for the rutorrent directory:

` <VirtualHost *:80> ServerAdmin webmaster@localhost

DocumentRoot /var/www/html Options FollowSymLinks AllowOverride All <Directory /var/www/html/> Options -Indexes FollowSymLinks MultiViews AllowOverride None Order allow,deny allow from all

ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/ <Directory "/usr/lib/cgi-bin"> AllowOverride None Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch Order allow,deny Allow from all

ErrorLog ${APACHE_LOG_DIR}/error.log

Possible values include: debug, info, notice, warn, error, crit, alert, emerg.

LogLevel warn

CustomLog ${APACHE_LOG_DIR}/access.log combined

<Location /rutorrent> AuthType Digest AuthName "rutorrent" AuthDigestDomain /var/www/html/rutorrent/ http://192.168.1.92/rutorrent AuthDigestProvider file AuthUserFile /etc/apache2/.htpasswd Require valid-user SetEnv R_ENV "/var/www/html/rutorrent"

<VirtualHost *:443> ServerAdmin webmaster@localhost ServerName 192.168.1.92:443

SSLEngine on SSLCertificateFile /etc/apache2/ssl/apache.pem

DocumentRoot /var/www/html/ Options FollowSymLinks AllowOverride All <Directory /var/www/html/> Options -Indexes FollowSymLinks MultiViews AllowOverride None Order allow,deny allow from all

ErrorLog ${APACHE_LOG_DIR}/error.log

Possible values include: debug, info, notice, warn, error, crit, alert, emerg.

LogLevel warn

CustomLog ${APACHE_LOG_DIR}/access.log combined

<Location /rutorrent> AuthType Digest AuthName "rutorrent" AuthDigestDomain /var/www/html/rutorrent/ http://192.168.1.92/rutorrent AuthDigestProvider file AuthUserFile /etc/apache2/.htpasswd Require valid-user SetEnv R_ENV "/var/www/html/rutorrent" `

Enable SSL for your site:

$ sudo a2ensite default-ssl

Modify Apache ports configuration:

$ sudo nano /etc/apache2/ports.conf

replace with this information

` NameVirtualHost *:80 Listen 80

NameVirtualHost *:443 Listen 443 Listen 443 `

Restart Apache

$ systemctl reload apache2

Confirm that Apache and SSL are working by navigating to your server in a browser with the https:// prefix: https://192.168.1.92

You will likely receive a warning from your browser suggesting that the site is insecure. This is because of our self-signed certificate; ignore it and proceed.

You should see a page containing the text, "It works!" Or with new versions of Ubuntu, you'll see the "Apache2 Ubuntu Default Page."

Modify PHP Settings

If you ever find yourself uploading one or two dozen torrents at a time, you may want to adjust the PHP settings to allow for larger file uploads.

First, create a new phpinfo() file. There are other, quicker ways to find the active php.ini file, but this is a surefire method that won't leave you editing one of the inactive files.

$ echo '<?php phpinfo(); ?>' | sudo tee /var/www/html/info.php

Go to 192.168.1.92/info.php in your browser.

Find the line that says Loaded Configuration file and then copy and paste its location in the following command, replacing the bold string:

$ sudo nano **/etc/php/7.0/apache2/php.ini**

Use Ctrl+W in Nano to find and modify the following lines:

upload_max_filesize = 64M max_file_uploads = 200 post_max_size = 128M

Remove the file info.php to reduce security risks.

$ sudo rm /var/www/html/info.php

Restart Apache

$ systemctl reload apache2

RUTORRENT

Install ruTorrent Dependencies

Ubuntu 16.4 LTS:

$ sudo apt-get install zip unzip zlib1g-dev ffmpeg mediainfo $ sudo apt-get install unrar rar

Download ruTorrent

Download ruTorrent from the project's Github repository, remove the packaged plugins directory, then replace it with the plugins from the repository. The following commands will download the latest versions of ruTorrent and plugins. No need to find the latest versions like in previous steps.

`$ cd /var/www/html $ sudo git clone https://github.com/Novik/ruTorrent.git rutorrent $ sudo rm -r rutorrent/plugins $ sudo svn checkout https://github.com/Novik/ruTorrent/trunk/plugins rutorrent/plugins

Configure ruTorrent

Transfer ownership of rutorrent files to webserver so that they are accessible:

$ sudo chown -R www-data:www-data rutorrent $ sudo chmod -R 755 rutorrent

Edit the ruTorrent configuration file:

$ sudo nano rutorrent/conf/config.php

replace these lines with the info below

` $log_file = '/tmp/rutorrent_errors.log'; $topDirectory = '/home/pi/share/'; $pathToExternals = array( "php" => '/usr/bin/php', "curl" => '/usr/bin/curl', "gzip" => '/bin/gzip', "id" => '/usr/bin/id', "stat" => '/usr/bin/stat', );

Those modifications...

  • Changed the error log filename to differentiate it from other error logs.
  • Restricted the ruTorrent interface to /home/downloads.
  • Defined the paths to ruTorrent dependencies.

Configure ruTorrent Plugins

ruTorrent has extended functionality beyond basic interface with rTorrent via a robust set of plugins. The plugins.ini file allows you to either hardcode an on/off state for individual plugins, or set them as user-defined, which allows you to determine their state within the ruTorrent web GUI.

This alphabetized version of plugins.ini enables all of the (subjectively) most useful plugins, and the additional optional plugins you can choose to install later in this guide. Enable/disable plugins as you see fit (the more plugins enabled, the longer ruTorrent will take to load), and if you don't know what something does, leave it set as user-defined, and explore the features in the web GUI.

$ sudo rm -f /var/www/html/rutorrent/conf/plugins.ini $ sudo nano /var/www/html/rutorrent/conf/plugins.ini

` ;; Plugins permissions. ;; If flag is not found in plugin section, corresponding flag from "default" section is used. ;; If flag is not found in "default" section, it is assumed to be "yes". ;; ;; For setting individual plugin permissions you must write something like that: ;; ;; [ratio] ;; enabled = yes ;; also may be "user-defined", in this case user can control plugins state from UI ;; canChangeToolbar = yes ;; canChangeMenu = yes ;; canChangeOptions = no ;; canChangeTabs = yes ;; canChangeColumns = yes ;; canChangeStatusBar = yes ;; canChangeCategory = yes ;; canBeShutdowned = yes

[default] enabled = user-defined canChangeToolbar = yes canChangeMenu = yes canChangeOptions = yes canChangeTabs = yes canChangeColumns = yes canChangeStatusBar = yes canChangeCategory = yes canBeShutdowned = yes

[_getdir] enabled = yes

[_task] enabled = yes

[autotools] enabled = user-defined

[chat] enabled = no

[check_port] enabled = no

[chunks] enabled = user-defined

[cookies] enabled = user-defined

[cpuload] enabled = user-defined

[create] enabled = user-defined

[data] enabled = user-defined

[datadir] enabled = yes

[diskspace] enabled = user-defined

[edit] enabled = user-defined

[erasedata] enabled = user-defined

[extratio] enabled = user-defined

[extsearch] enabled = user-defined

[feeds] enabled = no

[filedrop] enabled = user-defined

[filemanager] enabled = yes

[fileshare] enabled = yes

[geoip] enabled = user-defined

[history] enabled = no

[httprpc] canBeShutdowned = no

[instantsearch] enabled = no

[ipad] enabled = user-defined

[logoff] enabled = yes

[loginmgr] enabled = no

[mediainfo] enabled = yes

[mediastream] enabled = yes

[pausewebui] enabled = yes

[ratio] enabled = user-defined

[ratiocolor] enabled = user-defined

[retrackers] enabled = no

[rpc] enabled = no

[rss] enabled = user-defined

[rssurlrewrite] enabled = no

[rutracker_check] enabled = no

[scheduler] enabled = user-defined

[screenshots] enabled = yes

[seedingtime] enabled = yes

[show_peers_like_wtorrent] enabled = user-defined

[source] enabled = yes

[theme] enabled = yes

[throttle] enabled = user-defined

[titlebar] enabled = user-defined

[tracklabels] enabled = user-defined

[trafic] enabled = user-defined

[unpack] enabled = user-defined `

Create ruTorrent Credentials

Now let's create a username/password for ruTorrent. This is a different set of credentials than the SSH user account we created at the beginning of this process. It's more secure to pick different credentials than those you chose previously, but less convenient. It's your choice.

$ sudo htdigest -c /etc/apache2/.htpasswd rutorrent pi

Enter the password.

Status Report

You've now completed all the steps to run rTorrent and ruTorrent on your server. You can stop here, or add additional functionality to ruTorrent or to your server, like the ability to stream media to your local devices, and automatically download torrents that match custom filter rules.

Before we go any further, verify that everything is working as expected. It's easier to fix problems now with fewer components to troubleshoot.

Navigate to https://192.168.1.92/rutorrent

Make sure the GUI loads, and then try adding a torrent.

AUTODL-IRSSI

Autodl-irssi was redeveloped as a community project after the original developer abandoned the project. We'll be using the community version hosted on Github instead of the original project from Sourceforge.

Autodl-irssi has an automated install script, but it requires you to uninstall the web server you currently have installed so it can be reconfigured. We don't want to do that because we've already gone through a bit of trouble to get Apache configured how we want it.

Install Dependencies

$ sudo apt-get -y install irssi libarchive-zip-perl libnet-ssleay-perl libhtml-parser-perl libxml-libxml-perl libdigest-sha-perl libjson-perl libjson-xs-perl libxml-libxslt-perl php-xml

Install Autodl-irssi

` $ mkdir -p ~/.irssi/scripts/autorun $ cd ~/.irssi/scripts $ curl -sL http://git.io/vlcND | grep -Po '(?<="browser_download_url": ")(.*-v[\d.]+.zip)' | xargs wget --quiet -O autodl-irssi.zip $ unzip -o autodl-irssi.zip $ rm autodl-irssi.zip $ cp autodl-irssi.pl autorun/ $ mkdir -p ~/.autodl $ touch ~/.autodl/autodl.cfg

Install ruTorrent Plugin

$ cd /var/www/html/rutorrent/plugins $ sudo rm -rf autodl-irssi $ sudo git clone https://github.com/autodl-community/autodl-rutorrent.git autodl-irssi $ sudo cp autodl-irssi/_conf.php autodl-irssi/conf.php $ sudo chown -R www-data:www-data autodl-irssi

Configure Autodl-irssi

Edit plugin configuration:

$ sudo nano autodl-irssi/conf.php

Choose any port between 20000-65535 that you have not used previously. Generate a random password. It will never be used again, so it doesn't have to be memorable. The following password has been randomly generated for you, and will change each time this page reloads.

Input this information into autodl-irssi/conf.php.

$autodlPort = 50000; $autodlPassword = "598d92a7421b764e";

Modify ~/.autodl/autodl.cfg to include the same port/password:

$ nano ~/.autodl/autodl.cfg

[options] gui-server-port = 50000 gui-server-password = 598d92a7421b764e upload-type = rtorrent rt-dir = /home/pi/share rt-label = Auto

This [options] header...

  • gives Autodl-irssi the port and password you've chosen
  • sets the default upload type to rtorrent
  • sets default directory to /home/downloads/auto
  • sets default label for auto-downloaded torrents to "Auto"

All of these settings can be managed on a per-filter basis, excepting the server port and password. These are just defaults to fall back on in the event that you do not modify them in the filter rules.

Create ~/.autodl/autodl2.cfg and input rtorrent address. This should be the same address that you input in ~/.rtorrent.rc earlier in the installation process.

$ nano ~/.autodl/autodl2.cfg

[options] rt-address = 127.0.0.1:5000

This options header containing rt-address must be saved in autodl2.cfg instead of autodl.cfg.

Details of all available options can be found here.. You may adjust these settings manually in autodl.cfg, but you may find it easier to work within the plugin's GUI inside ruTorrent, which offers all the same customization options.

Create and detach a screen named "autodl" that will run the program "irssi":

$ screen -S autodl -fa -d -m irssi

Troubleshooting

If you recieve this Error downloading files. Make sure autodl-irssi is started and configured properly (eg. password, port number):

Its probably that irssi hasnt started correctly, open the terminal and enter

$ screen -S autodl -fa -d -m irssi

Clone this wiki locally