Skip to content

Archlinux

Andrew Parker edited this page Dec 20, 2018 · 23 revisions

Ultimate Torrent Setup

Introduction

Changes in this version

This guide accomplishes the same thing as the other guide but instead of Ubuntu as the OS and Apache as the webserver/reverse proxy, this guide uses Archlinux as the OS and Caddy as the webserver/reverse proxy.
Archlinux is requires an experienced Linux admin, so beginners should use the Ubuntu guide.

Assumptions

This guide will help you setup the ultimate automatic torrent downloading solution. You will setup and configure, on Archlinux, rTorrent+ruTorrent, Sonarr, Radarr and Caddy as a reverse proxy for all these. This guide assumes that you would like to be able to access all these interfaces from anywhere on the Internet (using a login form secured with an SSL certificate) and that you have a domain name you will use. If you don't have a domain name yet see the section called Domain Name and Dynamic DNS at the end of this guide. Your domain name should alredy be set up and pointing to your external ip address which in turn should be forwarding to your Archlinux box. The following ports need to be open in your firewall and forwarded to your Archlinux box: 80 and 443 for access to the web interfaces, and 22 if you want ssh access remotely. The port that rTorrent is configured to use needs to be open, in this guide its 49155 by default.

How it Works

We will be using the ruTorrent plugins autotools, ratio & extratio to accomplish what we want. The way these plugins work is best described by an example:
Say you have a directory /torrent for your torrent downloads. What you would do is create three sub dirs in that directory called watch, download and complete. Inside these directories will contain a mirrored directory structure for the different categories of torrents you download. So your structure might look like this:

So if you drop a torrent into /torrent/watch/tv/sonarr, the torrent download is started in /torrent/download/tv/sonarr. Also a label is automatically applied to the torrent based on the directory: in this example our torrent would receive the label tv/sonarr. Once the torrent is finished downloading, a hard link will be created in /torrent/complete/tv/sonarr. A hard link means that a duplicate file is made, but it shares the same data as the original. This is better than copying because it is instant and you don't have to duplicate the data on your hard drive. So now if we just have Sonarr watch the /torrent/complete/tv/sonarr directory it can process the hard linked files and move them to a final TV directory, AND we can continue to seed with the original file in /torrent/download/tv/sonarr with no problems. Even when we delete the file in the download directory, it won't affect the other hard link in the place where Sonarr placed it.
We'll also create some Ratio Rules that will seed a torrent of a specific label to a specified ratio and then automatically delete the torrent. So you won't have to monitor your torrents and manually clean them up when they've seeded enough, they will automatically seed to the perfect amount and then delete themselves.
The end result will be: you add a show to Sonarr, Sonarr will automatically search for new episodes and download the torrent file as soon as it's available. The torrent will be added and started in rTorrent. As soon as the download is complete, Sonarr will process the hard link of the data by renaming it nicely and placing it in a nice, organized TV Shows folder. Meanwhile rTorrent will still be seeding the original file until it reaches the defined ratio, and then will auto delete the torrent and the original file from the download dir. 100% automated TV downloading! Radarr does the same thing for movies.

Install rTorrent, ruTorrent, Sonarr, Radarr

Login as your user then execute these commands one line at a time.

Update Archlinux

sudo pacman -Syu

Make media group

Create a group named media. All the apps will be part of this group.

sudo groupadd --system media

sudo usermod -aG media $USER

rTorrent & ruTorrent

Install yay package manager and Prereqs

sudo pacman -S git

git clone https://aur.archlinux.org/yay.git

cd yay

makepkg -si

cd ~

sudo rm -r yay

yay -S zip unzip rar mediainfo ffmpeg php-fpm php-geoip rtorrent

yay --editor vim --save

yay --editmenu --save

yay -S caddy

When prompted to view diffs select N for None. When prompted to Edit the PKGBUILD file select A to edit all. Uncomment the following lines and save to continue:

http.jwt
http.login

Make Directories

Create the webserver root for Caddy

sudo mkdir -p /var/www/public

Create and change directory to where you are going to download all your torrents to. For an example, this guide will use /data.
On your server, you will probably have a large chunk of storage configured on a certain mount point. The mount point is where you will want to change directories to.
It's important to realize that /data is just an example path that this guide uses, therefore, whenever you see /data in this guide be sure to change it to what the path to your storage actually is.

sudo mkdir /data

cd /data

Then execute this command which will create the folder structure I illustrated earlier:

sudo mkdir -p torrent/{complete/{movie/radarr,music,tv/sonarr,game,book,software,other},download/{movie/radarr,music,tv/sonarr,game,book,software,other},watch/{movie/radarr,music,tv/sonarr,game,book,software,other}} Media/{Movies,'TV Shows'}

Make your user the owner of these folders and set the default permissions by executing these commands:

sudo chown -R $USER:media /data/*

sudo chmod -R 775 /data/*

or whatever your path is.
Then run the following to set the group ID and the default group ACLs on the data folders:

sudo find /data/* -type d -exec chmod g+s {} +

sudo find /data/* -type d -exec setfacl -m default:group::rwX {} +

Configure PHP and Caddy

Edit php configs

Edit /etc/php/php.ini and search for the line that contains date.timezone =. Set the value for your timezone from PHP Timezones. Mine looks like:

date.timezone = America/Denver

Edit /etc/php/php-fpm.d/www.conf and change group and listen.group to:

group = media
listen.group = media

Search for env[PATH] and uncomment the line by deleting the semicolon:

env[PATH] = /usr/local/bin:/usr/bin:/bin

Edit /etc/php/conf.d/geoip.ini and uncomment the line by deleting the semicolon:

extension=geoip.so

Add http user to media group and enable php-fpm service
sudo usermod -aG media http

sudo systemctl enable --now php-fpm.service

Create password for htpasswd authentication

These will be the credentials Caddy uses to authenticate you. It uses the username you are currently logged in as and a password you choose.

read -s -p "Enter Password:" password

echo -n "$USER:" | sudo tee /etc/caddy/passwd && openssl passwd -apr1 $password | sudo tee -a /etc/caddy/passwd

sudo chown http:http /etc/caddy/passwd

sudo chmod 600 /etc/caddy/passwd

Get Caddy config and enable the service
sudo curl https://raw.githubusercontent.com/xombiemp/ultimate-torrent-setup/master/caddy.conf -o /etc/caddy/caddy.conf

Edit /etc/caddy/caddy.conf and change this to your actual domain name.

yourdomain.com {

sudo systemctl enable --now caddy.service

Configure rTorrent

Create rtorrent user and directories

sudo useradd -r -m -d /var/lib/rtorrent -U -G media -s /sbin/nologin rtorrent

sudo chmod 755 /var/lib/rtorrent

sudo mkdir -p /var/lib/rtorrent/session

sudo mkdir -p /etc/rtorrent

Get rTorrent config file:

sudo curl https://raw.githubusercontent.com/xombiemp/ultimate-torrent-setup/master/rtorrent.rc -o /etc/rtorrent/rtorrent.rc

Edit /etc/rtorrent/rtorrent.rc and look for where it says

/CHANGE/THIS/PATH

for the directory path and edit the path for your setup. In our example, the directory path is the download directory we created previously, /data/torrent/download. Look for

HTPASSWD_WEBAUTH_USER

at the bottom and change it to the user you created credentials for earlier (user your logged in as by default). Change any other random options that you want.

sudo chown -R rtorrent:media /var/lib/rtorrent/*

sudo curl https://raw.githubusercontent.com/xombiemp/ultimate-torrent-setup/master/rtorrent.service -o /etc/systemd/system/rtorrent.service

sudo systemctl enable --now rtorrent.service

ruTorrent

Install ruTorrent

The script update-rutorrent will install ruTorrent and plugins automatically. Then whenever you run it again it will update ruTorrent and plugins that have updates.

sudo curl https://raw.githubusercontent.com/xombiemp/ultimate-torrent-setup/master/update-rutorrent -o /usr/local/bin/update-rutorrent

Edit /usr/local/bin/update-rutorrent and change:

webserver_service="caddy.service"

sudo chmod +x /usr/local/bin/update-rutorrent

sudo update-rutorrent

Edit ruTorrent configs

sudo curl https://raw.githubusercontent.com/xombiemp/ultimate-torrent-setup/master/plugins.ini -o /var/www/rutorrent/conf/plugins.ini

Edit /var/www/rutorrent/conf/plugins.ini
Edit to disable the plugins you don't want to use. You can leave it as it is to use the plugins that I use. The ones you have to keep are autotools, ratio, extratio and throttle.

Edit /var/www/rutorrent/conf/config.php
Change:

$saveUploadedTorrents = false;

Change $topDirectory to the top directory where your torrents are downloaded. In our example:

$topDirectory = '/data/';

Comment out existing $scgi_port and $scgi_host. Uncomment the ones below and change:

$scgi_port = 0;
$scgi_host = "unix:///var/lib/rtorrent/rtorrent.sock";

Change:

$profileMask = 0775;

Edit /var/www/rutorrent/plugins/autotools/conf.php
The $autowatch_interval variable is how often in seconds it looks in the watch folders for new torrent files. I changed mine to:

$autowatch_interval = 60;

Edit /var/www/rutorrent/plugins/filemanager/conf.php
Set the mkdperm to:

$fm['mkdperm'] = 775;

sudo chmod +x /var/www/rutorrent/plugins/filemanager/scripts/*

Edit /var/www/rutorrent/plugins/fileshare/conf.php
Set the $downloadpath variable to match the domain you will use to access your site:

$downloadpath = 'https://yourdomain.com/public/share.php';

sudo ln -s /var/www/rutorrent/plugins/fileshare/share.php /var/www/public/

Edit /var/www/rutorrent/plugins/unpack/conf.php
Set the following variable values:

$deleteAutoArchives = true;
$unpackToTemp = true;

Set permissions on share directory

sudo chown -R http:media /var/www/rutorrent/share/*

sudo find /var/www/rutorrent/share/* -type d -exec chmod 775 {} \;

sudo find /var/www/rutorrent/share/* -type f -exec chmod 664 {} \;

sudo systemctl restart rtorrent.service

Sonarr

Install Sonarr and Configure

yay -S sonarr

sudo usermod -aG media sonarr

sudo systemctl enable --now sonarr.service

sudo systemctl stop sonarr.service

Edit /var/lib/sonarr/config.xml and change:

<UrlBase>/sonarr</UrlBase>

sudo systemctl start sonarr.service

Radarr

Install Radarr Configure

yay -S radarr

sudo usermod -aG media radarr

sudo systemctl enable --now radarr.service

sudo systemctl stop radarr.service

Edit /var/lib/radarr/config.xml and change:

<UrlBase>/radarr</UrlBase>

sudo systemctl start radarr.service

Configure the GUI Settings

ruTorrent

First browse to https://yourdomain.com/rutorrent
You will be presented with the login window:

Login with the username and password you created earlier.

Click on the gear cog to enter the settings.
In Autotools enable all the options and browse to your complete and watch directories. Also, be sure to select Hard Link for the operation type:

In History I only check Deletion. This is nice because Sonarr could download a torrent, seed it to 2.0, and delete it all while you are sleeping. So the History plugin will let you see a record of when it was deleted and what your ratio was, just for your sanity:

In Unpack check enable autounpacking:

In Ratio Groups set up a default group and a Sonarr group:

Click ok. Then click on the wrench/screwdriver next to the gear cog and click on Ratio Rules. Set up a rule for Sonarr:

You can setup another Ratio Rule for Radarr downloads too, if you want. Alternatively, you could set up ratio rules for each individual tracker by selecting "One of torrent's tracker URLs contain" from the drop down list.

Now when you add a torrent you just click on the directory button and choose which category it is. Then it will automatically receive that label and it will download to the proper directory.

Sonarr

Now browse to https://yourdomain.com/sonarr
Click on Settings and you'll see the Media Managment tab.

Move the switch to Shown next to Advanced Settings. Switch Rename Episodes to Yes. Set the renaming formats to the way you want. Mine are set to conform to Plex naming standards.

Enable Delete empty folders and Ignore Deleted Episodes.

Change the File chmod mask to 0664 and the Folder chmod mask t0 0775 and the chown Group to media.
Click the Save button.

Click on the Indexers tab.

Click the plus button to add your desired providers. Configure the provider with the info it asks for, which you will usually find in your respective rss feed url for the tracker. If your tracker does not support search, I would suggest checking out Jackett. It is a separate webapp that adds search capabilities to many trackers. I haven't used it personally, but I've heard it works well.

Click on the Download Client tab.

Click the plus sign and click Torrent Blackhole. For the Torrent Folder browse to your sonarr watch directory. In our example it would be /data/torrent/watch/tv/sonarr. For the Watch Folder browse to your sonarr complete folder. In our example it would be /data/torrent/complete/tv/sonarr. Turn Read Only to No.

Click on the General tab.

Turn Open browser on start to No. Change Log Level to Debug.

Click on Series -> Add Series -> Import Existing Series On Disk
Browse to your TV Shows folder. In our example it would be /data/Media/TV Shows/

Click the close button.

Radarr

Now browse to https://yourdomain.com/radarr
Click on Settings and you'll see the Media Managment tab.

Move the switch to Shown next to Advanced Settings. Switch Rename Movies to Yes. Set the renaming formats to the way you want. Mine are set to conform to Plex naming standards.

Enable Ignore Deleted Movies. Set File chmod mask to 0664 and Folder chmod mask to 0775 and chown Group to media.
Click the Save button.

Click on the Indexers tab.

Click the plus button to add your desired providers. Configure the provider with the info it asks for, which you will usually find in your respective rss feed url for the tracker. (Required Flags is optional. My setting makes it so it will only download approved torrents from PTP.) If your tracker does not support search, I would suggest checking out Jackett. It is a separate webapp that adds search capabilities to many trackers. I haven't used it personally, but I've heard it works well.

Click on the Download Client tab.

Click the plus sign and click Torrent Blackhole. For the Torrent Folder browse to your radarr watch directory. In our example it would be /data/torrent/watch/movie/radarr. For the Watch Folder browse to your radarr complete folder. In our example it would be /data/torrent/complete/movie/radarr. Turn Read Only to No.

(Optional) Click on the Custom Formats tab.
Custom formats are a very powerful advanced feature. You can use them to fine tune how you search for releases. This example is for PTP.

Click the plus button and click Custom. These settings match any release that is not labeled Scene by PTP.

Add another Custom format. These settings match Golden Popcorn releases from PTP.

(Optional cont.) Click on the Profiles tab.
Click on the Profile you plan to use.


Set a Custom Format Cutoff and set the order of the Custom Formats (higher in the list is more preferred). This example creates a profile that will download a scene release if it's the only release available, will upgrade to a non-scene release if/when it becomes available, and will upgrade to the Golden Popcorn release if/when it becomes available.

Click on the General tab.

Turn Open browser on start to No. Change Log Level to Debug.

Click on Add Movies -> Bulk Import Movies
Browse to your Movies folder. In our example it would be /data/Media/Movies/

Click Ok then click the green check mark.

Conclusion

Now that everything is configured you can add TV shows to Sonarr and movies to Radarr and watch the magic. You can update rTorrent, Sonarr, Radarr and Caddy using yay. You can keep ruTorrent up to date by running the update-rutorrent script again.

Enjoy 100% automated TV and movie downloading!

Optional Extras

These are some additional things you can do that make this setup even better.

Notifications

Both Sonarr and Radarr have the ability to notify you when they start a download and finish a download. My favorite provider, and the one I use, is Pushover. Pushover supports both iOS and Android and is simply a one time purchase rather than a monthly subscription.

Sonarr & Radarr

Click Settings -> Connect. Check Pushover (or your provider of choice) and configure the settings.

Now you will receive a notification when ever a show or movie starts and finishes downloading.

Mobile Access

Now that everything is setup, you'll probably find yourself wanting to access these interfaces from your mobile device. I have an iPhone, so all the screenshots will be from that, but since these are all webapps, this should work from any device.

ruTorrent

A mobile plugin was created by zebraxxl, but it appears he has abandoned it. I have created a fork of rutorrentMobile and made a number of enhancements. The update-rutorrent script is set to automatically install this plugin so it should already be installed. Now from your mobile browser, browse to https://yourdomain.com/rutorrent and you should see the mobile interface for rutorrent. Add to your mobile home screen to create a web app.

Sonarr & Radarr

Sonarr and Radarr have a responsive design that is very functional on a mobile device. From your mobile browser, browse to https://yourdomain.com/sonarr and you should see the interface for Sonarr. Add to your mobile home screen to create a web app. Do the same for Radarr.

Resilio Sync watch folders

Resilio Sync is like Dropbox, but instead of syncing to the cloud first, the folders sync from Peer to Peer. We can set up Resilio Sync on our watch directory so that we are able to drop .torrent files into those directories from any device. On iOS for instance, you can download a .torrent file in Safari and then use the Open with... option to place the file in one of the watch folders, depending on the category. Then Resilio Sync will sync that file to all the Peers connected to it, includng our Archlinux server, which means the .torrent file will be downloaded to the correct watch folder and picked up by ruTorrent immediately!

yay -S rslsync

sudo usermod -aG media rslsync

sudo systemctl edit rslsync.service

Add this to the file and save:

[Service]
UMask=0002

sudo systemctl enable --now rslsync.service

Now browse to https://yourdomain.com/sync
Fill in a username only and click Continue.

Fill in a name, agree to the terms and click the Get started button.

Click the + button and Standard Folder button:

Browse to your watch directory. In our example it is /data/torrent/watch/. Then click the Open button.

Now click the 3 dots menu next to the folder and click Preferences:

Configure it how you want. This is how I have mine configured.

Now you can click the Share button and use the Key to add your Desktop client or the QR code to add the mobile client.
When you download a torrent click the Open in > Copy to Sync option and then the Sync app will launch.

Just browse to the correct watch folder, based on the category of torrent, and then it will sync back to your Archlinux server and be picked up and started immediately by ruTorrent and receive the correct label based on the folder you placed it in.

Plex Media Server

In order to view all your media you will want to use a media server. My media server of choice is Plex and we can run Plex Media Server right on our Archlinux box that contains all our media.

yay -S plex-media-server-plexpass

sudo usermod -aG media plex

sudo systemctl enable --now plexmediaserver.service

From a computer on the same network as your Archlinux server, browse to http://archlinux.server.local.ip:32400/web and login with your Plex credentials.
If your Archlinux server is on a different network (in the cloud for example), you'll first need to set up an SSH tunnel so that you can access things as if they were local. This is only necessary for the initial setup.
Follow the instructions here at the bottom of the page where it says "On a Different Network" to set up the ssh tunnel.

Name the server and click Next.

Click Add Library.

Click Moves and click Next.

Browse to your Movies folder. In our example it was /data/Media/Movies

Click Add Library again and select TV Shows.

Browse to your TV Shows folder. In our example it was /data/Media/TV Shows

Click Next and then click Done.

Click the settings button in the top right and click the Server section. Click on the Library tab and click the Show Advanced button. Enable Update my library automatically. Enable thumbnail generation when media is added.

Click on Scheduled Tasks and enable all the tasks.

Edit any other settings you might want then restart Plex Media Server.

sudo systemctl restart plexmediaserver.service

Now that Plex Media Server is running you can access your media using one of the Plex clients and stream your media where ever you want! Plex will attempt to use UPnP to automatically configure your firewall to allow access remotly. If your router/firewall does not support that, you will need to manually open port 32400. Then in the Server settings enable Manually specify public port in the Remote Access settings.

Tautulli

Tautulli is a 3rd party application that you can run alongside your Plex Media Server to monitor activity and track various statistics. Most importantly, these statistics include what has been watched, who watched it, when and where they watched it, and how it was watched. You can also use it for notifications for recently added items to Plex libraries and start of playback, etc.

yay -S tautulli

sudo systemctl enable --now tautulli.service

sudo systemctl stop tautulli.service

Edit /var/lib/tautulli/config.ini and change:

http_root = /tautulli

sudo systemctl start tautulli.service

Now browse to https://yourdomain.com/tuatulli
Click Next to start the wizard.
Login to your Plex account and click Next.


Select your Plex instance on it's local IP Address and Click Verify. Then click Next.


Click Next through the other prompts and finally click Finish.

Click on the gear cogs in the top right to enter settings. Click the Show Advanced button and then click on the Web Interface menu.

Uncheck Launch Browser on Startup and check Enable HTTP Proxy. Click the Save button. (don't restart if it ask you to)

Click on the Plex Media Server Menu.

In the Logs Folder box paste in /var/lib/plex/Plex Media Server/Logs/. Check Monitor Plex Updates and choose your Update Channel and choose Linux - Fedora 64-bit for the Release. Check Monitor Plex Remote Access.

Click on the Notifications & Newsletter menu.

Check Group Notifications by Season or Album and Group Notifications by TV Show or Artist.

Click the Notification Agents menu and click Add new notification agent.

Configure your Pushover (or other provider) settings. Then click the Triggers tab.

Check the boxes for the events you want notifications for. I check Playback Start, Buffer Warning, User Concurrent Streams, Recently Added, Plex Update Available, Tautulli Update Available.
Click the Test Notifications tab.

Click the Test button and confirm that you receive the test notification and then click Save.

Domain Name and Dynamic DNS

To be able to access your resources remotely and secured with an SSL certificate, you will need to set up a domain name. You'll need to purchase a domain name from a registrar and then configure the DNS records to point to your IP address. Most often, with residential ISP accounts, you will have a dynamic IP address that changes often. In order to configure a domain name to point to your IP address you will need to use a dynamic dns service that will update your DNS records whenever your IP address changes. The registrar I chose, Namecheap, is inexpensive and also includes a free dynamic dns service. In this section I'll show you how to purchase your domain name and configure the dynamic dns client to run on the Archlinux machine.
Browse to https://www.namecheap.com and search for a domain name you want in the search box. Once you find a domain you want that is available, continue on to purchase the domain name.
Once you have your domain name purchased, follow the instructions here to enable Dynamic DNS on your account and get your Dynamic DNS Password. Then follow the instructions here to create the host record that will be updated dynamically.
Now we'll install the dynamic DNS client on the Archlinux machine.

yay -S ddclient

sudo curl https://raw.githubusercontent.com/xombiemp/ultimate-torrent-setup/master/ddclient.conf -o /etc/ddclient/ddclient.conf

Edit /etc/ddclient/ddclient.conf
Change the login and password fields to be your domain name and your Dynamic DNS Password that we got earlier. For more information on this config file, check out this Knowlagebase Article.

sudo systemctl enable --now ddclient.service

The dynamic dns client should be working now and will automatically update your DNS records whenever your IP address changes. Check your DNS records in Namecheap to make sure that it has automatically added a DNS record.

Clone this wiki locally