Seedbox Raspberry Pi with Lighttpd, rTorrent, ruTorrent on Arch Linux


You might saw the tutorial, how to setup a seedbox using transmission on Raspbian. Now we'll see a different way to setup a seedbox on Raspberry Pi.

This time, I used Arch Linux. As programs I used Lighttpd as web server, rTorrent as consol torrent client, ruTorrent as web interface for rTorrent.
Here are the contents of this tutorial. Let's start.



Setup the SD card with Arch Linux


This is standard prcedure.

1. Go to Raspberry Pi Arch Linux and follow the instructions there.

You're all set. Don't forget the user-pass:

user: root
pass: root

You better create another user but since it's since it's not a matter of national security, you can use root as well.
To login from your computer, use

ssh root@RASPI_IP

2. Boot your device, and first thing is to update Arch Linux

pacman -Syu

3. Then create a new partition (it's very close to GUI)

cfdisk /dev/mmcblk0

Now format the partition:

mkfs.ext4 /dev/mmcblk0p3

NOTE: Usually it's mmcblk0p3. If you're not sure, see it with the command cat /proc/partitions. Sometimes it might be mmcblk0p5.

Create a directory to mount the partition (we'll use this partition to save the downloads):

mkdir /media/data

Now add partition to fstab to automount everytime you reboot.

nano /etc/fstab

# and add the following line
/dev/mmcblk0p3 /media/data defaults 1 0


Install the web server Lighttpd


You can use apache as alternative.

Install Lighttpd:

pacman -S lighttpd

Start the Lighttpd service

systemctl start lighttpd

If you open your web browser on the Raspberry Pi IP, you'll see the service running.
Systemd's way to check if the service is running, is the command

systemctl status lighttpd


Install and configure rTorrent


1. Install rTorrent

pacman -S rtorrent

Now, let's configure it.

First of all copy the configuration file to your home folder (here is root).

cp /usr/share/doc/rtorrent/rtorrent.rc ~/.rtorrent.rc

Now create 2 directories under the partition /media/data (we created above)

mkdir /media/data/Torrents && mkdir /media/data/.session

If this command fails, run it one by one (before and after &&).

Now it's time to edit rtorrent.rc file.

nano ~/.rtorrent.rc

Here we set the exact path of the above 2 directories we created. Be sure you uncomment the lines.

# Default directory to save the downloaded torrents.
directory = /media/data/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 = /media/data/.session

Configure the port range.

port_range = 49164-49164

You can also cnfigure the encryption.

encryption = allow_incoming,try_outgoing,enable_retry

You can also enable the DHT service and set the port.

# 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

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

Enable also the peer exchange. The comment says that if you have private torrents, then don't enable it.

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

Now we can check if the rTorrent, works. Run:

rtorrent

Finally, install screen so you'll hide the cli interface of rTorrent.

pacman -S screen

Now create a systemd service for rTorrent.

nano /etc/systemd/system/rtorrent@.service

and add the following text:

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

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

[Install]
WantedBy=multi-user.target

Finally run the service:

systemctl start rtorrent@root

The commands to stop and see the status of the service are:

systemctl stop rtorrent@root
# and
systemctl status rtorrent@root

Now we need the web interface.


Install and configure ruTorrent


Now it's time to install a web interface for rTorrent.

1. Since it's not in the official repositories, you have to install it from AUR. To do so, install the following (some are dependencies, so it'll work properly).

# cd /srv/http

# wget https://dl.dropboxusercontent.com/u/20413076/raspberry/rutorrent/rutorrent-3.6.tar.gz

#tar xvfx rutorrent-3.6.tar.gz

#rm rutorrent-3.6.tar.gz

Alternative URL to download (Github):

https://rutorrent.googlecode.com/files/rutorrent-3.5.tar.gz
https://dl.dropboxusercontent.com/u/20413076/raspberry/rutorrent/rutorrent-3.5.tar.gz

2. Install ruTorrent. Add --noconfirm at the end, so it won't ask you for verification for PKGBUILD etc.

pacman -S mod_fastcgi php-cgi

3. Not it's time to edit the file /etc/lighttpd/lighttpd.conf

nano /etc/lighttpd/lighttpd.conf

Change

server.document-root = "/srv/http/"

with

server.document-root = "/srv/http/rutorrent/"

Commend the line that starts with:

#mimetype.assign = ( ".html" => "text/html" . . .

and add the following

mimetype.assign = (
".rpm" => "application/x-rpm",
".pdf" => "application/pdf",
".sig" => "application/pgp-signature",
".spl" => "application/futuresplash",
".class" => "application/octet-stream",
".ps" => "application/postscript",
".torrent" => "application/x-bittorrent",
".dvi" => "application/x-dvi",
".gz" => "application/x-gzip",
".pac" => "application/x-ns-proxy-autoconfig",
".swf" => "application/x-shockwave-flash",
".tar.gz" => "application/x-tgz",
".tgz" => "application/x-tgz",
".tar" => "application/x-tar",
".zip" => "application/zip",
".mp3" => "audio/mpeg",
".m3u" => "audio/x-mpegurl",
".wma" => "audio/x-ms-wma",
".wax" => "audio/x-ms-wax",
".ogg" => "application/ogg",
".wav" => "audio/x-wav",
".gif" => "image/gif",
".jar" => "application/x-java-archive",
".jpg" => "image/jpeg",
".jpeg" => "image/jpeg",
".png" => "image/png",
".xbm" => "image/x-xbitmap",
".xpm" => "image/x-xpixmap",
".xwd" => "image/x-xwindowdump",
".css" => "text/css",
".html" => "text/html",
".htm" => "text/html",
".js" => "text/javascript",
".asc" => "text/plain",
".c" => "text/plain",
".cpp" => "text/plain",
".log" => "text/plain",
".conf" => "text/plain",
".text" => "text/plain",
".txt" => "text/plain",
".dtd" => "text/xml",
".xml" => "text/xml",
".mpeg" => "video/mpeg",
".mpg" => "video/mpeg",
".mov" => "video/quicktime",
".qt" => "video/quicktime",
".avi" => "video/x-msvideo",
".asf" => "video/x-ms-asf",
".asx" => "video/x-ms-asf",
".wmv" => "video/x-ms-wmv",
".bz2" => "application/x-bzip",
".tbz" => "application/x-bzip-compressed-tar",
".tar.bz2" => "application/x-bzip-compressed-tar",
# default mime type
"" => "application/octet-stream",
)

We have activated the PHP for Lighttpd

# Required for Lighttpd + PHP
server.modules += ( "mod_fastcgi" )

fastcgi.server = ( ".php" => ((
"bin-path" => "/usr/bin/php-cgi",
"socket" => "/tmp/php.socket"
)))

4. Edit the file /etc/php/php.ini:

nano /etc/php/php.ini

Go to the line 307 and it has to look like:

open_basedir = /srv/http/:/home/:/tmp/:/usr/share/pear/:/usr/share/webapps/:/etc/webapps/:/usr/bin/

5. Restard the web server

systemctl restart lighttpd

6. Open with your browser your Raspberry's IP.

Next step is to connect ruTorrent with rTorrent.


Connect rTorrent with ruTorrent


1. Let's edit rtorrent.rc file.

nano ~/.rtorrent.rc

Add the following lines at the end of the file.

# Socket CGI
scgi_port = localhost:8080

2. Edit the file /usr/share/webapps/rutorrent/conf/config.php

nano /srv/http/rutorrent/conf/config.php

Change the port (line 30).

$scgi_port = 8080;

3. Edit the file /etc/lighttpd/lighttpd.conf

nano /etc/lighttpd/lighttpd.conf

Add the following lines, before eveything else.

# Communication rTorrent <-> ruTorrent
server.modules += ( "mod_scgi" )

scgi.server = (
"/RPC2" =>
( "127.0.0.1" =>
(
"host" => "127.0.0.1",
"port" => 8080,
"check-local" => "disable"
)
)
)

4. Now it's time to change the permissions so you won't have any problems.

chown -R http /srv/http/rutorrent
chown -R http /srv/http/rutorrent

You have to create a folder in the tmp folder and change the persmissions.

mkdir /tmp/rutorrent && chmod 777 /tmp/rutorrent

Now edid the file /usr/share/webapps/rutorrent/conf/config.php

nano /srv/http/rutorrent/conf/config.php

and change the value $tempDirectory = null; to the following

$tempDirectory = "/tmp/rutorrent/";

Finally, restart the services rtorrent and lighttpd

systemctl restart rtorrent@root
systemctl restart lighttpd

Open your browser to your Raspberry IP and you'll all set.


Final configuration of plugins and error correction


Problem: rTorrent cannot have access to program's 'id'.

Solution: Edit /usr/lib/systemd/system/lighttpd.service

nano /usr/lib/systemd/system/lighttpd.service

Change the line

PrivateTmp=true

with

PrivateTmp=false

and restart services

systemctl --system daemon-reload
# and
systemctl restart lighttpd

Problem: Webserver cannot have access to program ‘mediainfo/ffmpeg’ + Error rutracker_check

Solution: Install the programs.

pacman -S ffmpeg mediainfo

If you use them, you can disable them.

nano /usr/share/webapps/rutorrent/conf/plugins.ini

and change the following to

[mediainfo]
enabled = no
[screenshots]
enabled = no
[rutracker_check]
enabled = no

Problem: You cannot find unzip and unrar.

Solution: Install them.

pacman -S unzip unrar


Authentication and SSL


You can use your seedbox. Now you'll have a user name/password, SSL authentication and HTTPS.

1. You have to install Apache. Although we use another webserver, we'll use the tool htdigest.

pacman -S apache

2. Create the file that contains the username and the password.

htdigest -c /etc/lighttpd/.auth 'Username_Password_4_Torrent' root

You'll be asked for a password.

3. Edit the file /etc/lighttpd/lighttpd.conf

nano /etc/lighttpd/lighttpd.conf

Find the lines

# Required for Lighttpd + PHP
server.modules += ( "mod_fastcgi" )

and paste before them the following lines

# Server Authentication
server.modules += ( "mod_auth" )

auth.debug = 0
auth.backend = "htdigest"
auth.backend.htdigest.userfile = "/etc/lighttpd/.auth"

auth.require = ( "/" => (
"method" => "digest",
"realm" => "Username_Password_4_Torrent",
"require" => "valid-user"
))

Restart the service

systemctl restart lighttpd

Now if you open the web browser, you'll be asked for a username (root) and password (the one you just gave).

Next step is to have the SSL authentication and encryption between your computer and the Raspberry Pi.

4. Check if you have installed the package ca-certificates. If not, then install it.

pacman -S ca-certificates

Create the folder for certifications.

mkdir /etc/lighttpd/certs

and create the certification.

openssl req -new -x509 -newkey rsa:2048 -keyout /etc/lighttpd/certs/lighttpd.pem -out /etc/lighttpd/certs/lighttpd.pem -days 730 -nodes

5. Configure (for the last time) the Lighttpd webserver.

nano /etc/lighttpd/lighttpd.conf

add the code

# SSL Encryption
#$SERVER["socket"] == ":443" {
ssl.engine = "enable"
ssl.pemfile = "/etc/lighttpd/certs/lighttpd.pem"
#}

6. Change the 5th line to the port 443.

server.port = 443

7. Restart the service.

systemctl restart lighttpd

Now open your web browser to your Raspberry Pi IP. You'll be asked to accept the certification.

Some wiki pages:
Rutorrent with lighttpd
Lighttpd and php-fpm

Check out the conectivity:
Torrent seedbox on Raspberry Pi

Δεν υπάρχουν σχόλια

Από το Blogger.