Install ruTorrent on xbian

Install and configure apache server:
sudo apt-get install apache2 apache2-utils libapache2-mod-php5
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 or add the following lines:

Timeout 30
ServerSignature Off
ServerTokens Prod

Restart Apache

sudo service apache2 restart

Dependencies:
sudo apt-get install zip unzip zlib1g-dev ffmpeg mediainfo git
sudo apt-get install unrar rar

sudo apt-get install rtorrent

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

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/downloads

# 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/downloads/.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 = 55950-56000

# Start opening ports at a random position within the port range.
port_random = yes

# 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

Change or add the following lines accordingly:

directory = /home/downloads
session = /home/downloads/.session
schedule = watch_directory,5,5,load_start=/home/downloads/~watch/*.torrent
schedule = low_diskspace,5,60,close_low_diskspace=10240M
port_range = 55950-56000
port_random = yes
check_hash = yes
use_udp_trackers = yes
encryption = allow_incoming,enable_retry,prefer_plaintext
dht = disable
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 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.

sudo nano /etc/init.d/rtorrent
Paste the contents of this file into the terminal. Many thanks to Greg Methvin for the original script, and Max Power for the fork designed to work specifically with ruTorrent and XML-RPC.

#!/bin/bash
### BEGIN INIT INFO
# Provides:          rtorrent
# Required-Start:    $local_fs $remote_fs $network $syslog
# Required-Stop:     $local_fs $remote_fs $network $syslog
# Default-Start:     2 3 4 5
# Default-Stop:      0 1 6
# Short-Description: Start/stop rtorrent daemon
### END INIT INFO

# ------------------------------------------------------------------------------
# /etc/init.d/rtorrent
#
# This script is an init script to run rtorrent in the background, using a
# screen. The script was designed and tested for Debian systems, but may work on
# other systems. On Debian, enable it by moving the script to
# "/etc/init.d/rtorrent" and issuing the command
# "update-rc.d rtorrent defaults 99"
#    ____                _ _
#   / ___|  ___  ___  __| | |__   _____  __
#   \___ \ / _ \/ _ \/ _` | '_ \ / _ \ \/ /
#    ___) |  __/  __/ (_| | |_) | (_) >  <
#   |____/ \___|\___|\__,_|_.__/ \___/_/\_\
#
# @see http://methvin.net/scripts/rtorrent
# @see http://tldp.org/LDP/abs/html/
# ------------------------------------------------------------------------------

## Username to run rtorrent under, make sure you have a .rtorrent.rc in the
## home directory of this user!
USER=""

## Absolute path to the rtorrent binary.
## run "which rtorrent"
RTORRENT="/usr/local/bin/rtorrent"

## Absolute path to the screen binary.
SCREEN="/usr/bin/screen"

## Name of the screen session, you can then "screen -r rtorrent" to get it back
## to the foreground and work with it on your shell.
SCREEN_NAME="rtorrent"

## Absolute path to rtorrent's PID file.
PIDFILE="/var/run/rtorrent.pid"

## Absolute path to rtorrent's XMLRPC socket.
SOCKET="/var/run/rtorrent/rpc.socket"

## Check if the socket exists and if it exists delete it.
delete_socket() {
if [[ -e $SOCKET ]]; then
rm -f $SOCKET
fi
}

case "$1" in
## Start rtorrent in the background.
start)
echo "Starting rtorrent."
delete_socket
start-stop-daemon --start --background --oknodo \
--pidfile "$PIDFILE" --make-pidfile \
--chuid $USER \
--exec $SCREEN -- -DmUS $SCREEN_NAME $RTORRENT
if [[ $? -ne 0 ]]; then
echo "Error: rtorrent failed to start."
exit 1
fi
echo "rtorrent started successfully."
;;

## Stop rtorrent.
stop)
echo "Stopping rtorrent."
start-stop-daemon --stop --oknodo --pidfile "$PIDFILE"
if [[ $? -ne 0 ]]; then
echo "Error: failed to stop rtorrent process."
exit 1
fi
delete_socket
echo "rtorrent stopped successfully."
;;

## Restart rtorrent.
restart)
"$0" stop
sleep 1
"$0" start || exit 1
;;

## Print usage information if the user gives an invalid option.
*)
echo "Usage: $0 [start|stop|restart]"
exit 1
;;

esac

Set permissions and install the init script.

sudo chmod +x /etc/init.d/rtorrent
sudo update-rc.d rtorrent defaults 99


Download ruTorrent from the project’s Github repository.

cd /var/www/html
sudo git clone https://github.com/Novik/ruTorrent.git rutorrent

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
$log_file = ‘/tmp/rutorrent_errors.log’;
$topDirectory = ‘/home/downloads/’;
$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

Finall
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:///rutorrent

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

TROUBLESHOOTING
Apache Error Logs
Debian/Ubuntu: /var/log/apache2/error.log

CentOS: /var/log/httpd/error_log

rTorrent won’t start after reboot
If you find that rtorrent will not start on reboot, try to start rtorrent manually:

rtorrent
You’ll likely get the following error:

rtorrent: Could not lock session directory: “/home/downloads/.session/”, held by “:+XXXX”.
This can happen if your system crashes, or if you run out of disk space. To resolve the issue, delete rtorrent.lock from the session directory.

sudo rm -f /home/downloads/.session/rtorrent.lock
Now rtorrent should start, and you can reboot or start a new screen session for rtorrent:

screen -S rtorrent -fa -d -m rtorrent

More example for rtorrent .rtorrent.rc:

#custom1 set here. This is the folder to move to on completed downloads
#You can remove d.set_directory=/xxxx/neondemon/private/rtorrent/data/; this just set the folder the files are downloaded to before being moved 
schedule = watch_directory,5,60,load_start=/xxxx/neondemon/private/rtorrent/sickrage/*.torrent,d.set_directory=/xxxx/neondemon/private/rtorrent/data/;d.set_custom1=/xxxx/neondemon/private/rtorrent/data/_SickRage/
schedule = untied_directory, 5, 60, stop_untied=

schedule = low_diskspace, 5, 120, close_low_diskspace=100M


#This should do what you want it to. You have to set the folder to move to before actually moving or the files won't seed properly
system.method.set_key = event.download.finished,move_complete,"d.set_directory=$d.get_custom1=;execute=mkdir,-p,$d.get_custom1=;execute=mv,-u,$d.get_base_path=,$d.getcustom1"