Installing rTorrent/rutorrent under nginx

Start with a fresh and updated install of Debian Jessie.

# apt-get update && apt-get dist-upgrade

Then install some packages:

# apt-get install nginx rtorrent php5-fpm php5-cli curl git-core

Then create a new user, so that you don’t act silly and run everything under root.
(I use a dedicated vm, so I already had a user created during the install phase.)

Nginx-config:
# editor /etc/nginx/sites-enabled/default

upstream php-handler {
server unix:/var/run/php5-fpm.sock;
}
server {
listen 80;
server_name download.internal.local;
fastcgi_buffers 64 4K;
root /var/www/html;
index index.html;
error_page 404 /index.html;
location /RPC2 {
include scgi_params;
scgi_pass unix:/tmp/rpc.socket;
}
location ~ ^/(conf|share|\.ht|db_structure\.xml|README) {
deny all;
}
location ~ \.php$ {
fastcgi_split_path_info ^(.+\.php)(.*)$;
fastcgi_pass php-handler;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
fastcgi_param QUERY_STRING $query_string;
fastcgi_param REQUEST_METHOD $request_method;
fastcgi_param CONTENT_TYPE $content_type;
fastcgi_param CONTENT_LENGTH $content_length;
fastcgi_intercept_errors on;
fastcgi_ignore_client_abort off;
fastcgi_connect_timeout 60;
fastcgi_send_timeout 180;
fastcgi_read_timeout 180;
fastcgi_buffer_size 128k;
fastcgi_buffers 4 256k;
fastcgi_busy_buffers_size 256k;
fastcgi_temp_file_write_size 256k;
}
location ~* ^.+\.(jpg|jpeg|gif|bmp|ico|png|css|js|swf|svg)$ {
expires 30d;
access_log off;
}
}

Save the file, dont bother restart nginx.

Now to autostart rTorrent on each boot:

# editor /lib/systemd/system/rtorrent.service

[Unit]
 Description=rTorrent
 After=network.target

[Service]
 User=CHANGEME
 Group=users
 Type=forking
 KillMode=none
 Restart=always
 ExecStart=/usr/bin/screen -d -m -fa -S rtorrent /usr/bin/rtorrent
 ExecStop=/usr/bin/killall -w -s 2 /usr/bin/rtorrent
 WorkingDirectory=%h

[Install]
 WantedBy=multi-user.target

Change User to the username you allocated, save and close the file, and enable the service:
# systemctl enable rtorrent

 

Change context to the defined user;
# su -l <username>
Create the session-directory:
$ mkdir .session

Create config for rTorrent
$ editor .rtorrent.rc

download_rate = 1248
 upload_rate = 256
 directory = /mnt/
 session = /home/CHANGEME/.session
 port_range = 9500-9500
 port_random = yes
 encryption=allow_incoming,try_outgoing,enable_retry
 dht = disable
 set_dht_port = 9501
 peer_exchange = yes
 scgi_local = /tmp/rpc.socket
 schedule = chmod,0,0,"execute=chmod,777,/tmp/rpc.socket"
 encoding_list = UTF-8
 system.method.set_key =
 execute = {sh,-c,/usr/bin/php /var/www/html/php/initplugins.php &}

Consider changing directory, port-ranges and rates to your needs.
Save and close the file.

Change to web-directory, and checkout ruTorrent.

# cd /var/www/html/

# git clone https://github.com/Novik/ruTorrent .
(if this complains that the dir is not empty, do “# rm index.nginx-debian.html” first.)

When done, reconfigure ruTorrent for socket-communication:
# editor conf/config.php

Comment out $scgi_port and $scgi_host.
Add:

$scgi_port = 0;
$scgi_host = "unix:///tmp/rpc.socket";

Also fill in the path to curl ( /usr/bin/curl ).
I also change topDirectory to the dir my downloads should go, makes for easier browsing. (remember the trailing /)

Fix some permission issues,
# chown -R www-data share/

Save and close the file, technically ruTorrent/rTorrent works now – but all plugins are enabled which will generate some errors, and they are technically not needed.

# sed 's/ user-defined/ no/g' conf/plugins.ini -i

#editor conf/plugins.ini
Enable the plugins you want by typing in the following:

[loadavg]
enabled = yes

This enables the loadavg-plugin. (remove the ‘\’, for some reason wordpress

Reboot the case, and remember to open firewall. (by following this guide, that will be tcp/80, tcp/9500, and tcp/9501.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s