RTorrent wTorrent HowTo

From SynologyWiki
Jump to: navigation, search

This is a tutorial that explains how to install the bittorrent client rtorrent and a webinterface for rtorrent, wtorrent, on your synology NAS device. It should work on on the Synology DS107+, 207+ and CS407, and maybe others.

This guide isn't directed at total beginners. Some linux-knowledge and some understanding about how bittorrent works is implicitly required.

Contents

Get ipkg

You need ipkg working for the things described here. You should absolutely read this first: Tips to get you around your Synology box.

The important parts are those about gaining telnet access (3.) and about installing a bootstrap (4.). You must do this before continuing, if you haven't alreay.

install the needed packages

If you are running firmware 2.3 or above skip to step starting with "Step 2"

Step 1: Maarten Damen is no longer hosting the proceeding xmlrpc-c 1.11.00-3 package. Read further on how to compile xmlrpc-c yourself.

At the moment of writing this guide (May 10th), there's something wrong with the xmlrpc-c package from the "official" optware feed (xmlrpc-c v1.11.00-3). That's why you first need to enable Maartens feed (xmlrpc-c v1.11.00-2). To do this, add the following line to /opt/etc/ipkg.conf and remove/comment (# at the start of the line) any other lines there.

src maarten http://www.maartendamen.com/synoware

Now you can install xmlrpc-c from maarten using the following commands:

ipkg update
ipkg install xmlrpc-c

Once this is done, you can remove Maartens feed and re-enable the optware feed with this line:

src packages http://ipkg.nslu2-linux.org/feeds/optware/syno-x07/cross/unstable

At the moment of writing this paragraph (5 March 2010), the maarten repo is no longer hosting xmlrpc-c. You may compile xmlrpc-c "stable" version 1.16.25 from svn.

Step 2:

Login through SSH and install the following the packages if they aren't installed already:

ipkg update; ipkg install optware-devel gcc rtorrent libtorrent libcurl-dev apr-util php php-fcgi php-curl libcurl lighttpd sqlite svn screen

Next, you need to download the xmlrpc-c stable source code from the subversion repository, with these commands:

cd /root
REPOS=http://xmlrpc-c.svn.sourceforge.net/svnroot/xmlrpc-c/stable
svn checkout $REPOS xmlrpc-c

CD into the xmlrpc-c directory and run the configure script:

cd xmlrpc-c
./configure --prefix=/opt

If you are getting an gcc error while configuring xmlrpc-c, try

ipkg list_installed | grep optware

it shoudlnt give any output, because it's not installed then run the command again to install it:

ipkg install optware-devel

if it conflicts with wget, remove it and install wget-ssl instead. After that run the above command again.

If no errors, you may proceed with

make
make install

rtorrent

Create the file /root/.rtorrent.rc and make useful settings, take the example as an inspiration.

wget -O /root/.rtorrent.rc 'http://libtorrent.rakshasa.no/browser/trunk/rtorrent/doc/rtorrent.rc?rev=1057&format=raw' 
nano /root/.rtorrent.rc

I think the most important settings are directory, session and of course the port_range and dht_port.

I have set the directory to something in my public-share, and session to something in roots home-dir.

directory = /volume1/public/rt/
session = /root/.rtorrent

Whatever you choose, you'll need to create those two directories using mkdir. (e.g. mkdir /volume1/public/rt and mkdir /root/.rtorrent).

One more important setting is the scgi-port for xmlrpc. Just add a line to .rtorrent.rc that says

scgi_local = /root/.rtorrent/rpc.socket
schedule = chmod,0,0,"execute=chmod,777,/root/.rtorrent/rpc.socket"

This will open a local rpc socket through wich rtorrent and the wtorrent (the webinterface) can communicate. The second line will grant read/write access to the socket file to avoid permission errors.

Here is some typical settings concerning the torrent client (its depends of you xDSL connection).

# 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 = 10
max_peers_seed = 50

# Maximum number of simultanious uploads per torrent.
max_uploads = 15

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

# stop at ratio 1.5 with at least 50 MB uploaded, or else ratio 2.0
schedule = ratio,60,60,"stop_on_ratio=150,50M,200"

# Port range listening - Don't forget to open those ports on you firewall/router
port_range = 6891-6999

Now test it:

rtorrent

PHP

You'll need to enable two extensions in PHP so that wTorrent can write it's user-database. In the file /opt/etc/php.ini, look for the lines that say "extension=...so" and add/uncomment the following two lines:

extension=sqlite.so
extension=pdo.so
extension=pdo_sqlite.so

lighttpd

First, you'll need to enable mod_fastcgi in /opt/etc/lighttpd/lighttpd.conf and mod_scgi if it they aren't already enabled. Just remove the # at the beginning of the line to enable them. It might look something like this:

server.modules = (
                   "mod_access",
                   "mod_fastcgi",
                   "mod_scgi"
                  )

The second thing we need to do for lighttpd is to add the scgi socket. Add the following lines to the end of /opt/etc/lighttpd/lighttpd.conf:

scgi.server = (
               "/RPC2" =>
                 ( "127.0.0.1" =>
                   (
                     "socket" => "/root/.rtorrent/rpc.socket",
                     "check-local" => "disable",
                     "disable-time" => 0,
                   )
                 )
             )

It also may be necessary to replace

# server.event-handler = "freebsd-kqueue" # needed on OS X

with

server.event-handler = "poll"

Restart lighttpd when you're done. If you leave the console open, it'll give you some helpfull error-messages when something goes wrong. Thats also very useful later when setting up wTorrent.

 tail -f /opt/var/log/lighttpd/error.log


wtorrent

Go the the lighttpd webdirectory:

cd /opt/share/www/lighttpd

Get the newest version of wTorrent using svn:

svn co http://svn.wtorrent-project.org/wtorrent/trunk/wtorrent/

This should create a directory called "wtorrent" where all the files reside. Change into it!

cd wtorrent

Copy conf/sample.home.conf.php to conf/home.conf.php and edit it so it fits your need. Most important are the following settings:

define( 'RT_HOST',                      'localhost');
define( 'RT_PORT',                      8081);
define( 'RT_DIR',                       'RPC2/');
define( 'RT_AUTH',                      false);
define( 'RT_USER',                      'my_user');
define( 'RT_PASSWD',            'my_password');
  • DIR_EXEC (set it to /opt/share/www/lighttpd/wtorrent/
  • DIR_DOWNLOAD (set it to wherever you want your downloads to go, like "directory" in .rtorrent.rc)

Configuring S99rtorrent

This file will automatically start rtorrent when booting up your Syno NAS. The rtorrent ipkg installer must have created a file located here: /opt/etc/init.d/S99rtorrent. You must edit it in order to add and modify few lines (always replace the red parts by the green parts):

#dirlayout=RTORRENT_DEFAULT
#dirlayout=RTORRENT_DEFAULT
dirlayout=CUSTOM
user="p2p"
user="root"
config="/opt/etc/rtorrent.conf"
config="/root/.rtorrent.rc"
logfile="/opt/var/log/rtorrentInit.log" 
logfile="/root/rtorrentInit.log" 
SCRIPTNAME=/etc/init.d/$NAME 
SCRIPTNAME=/opt/etc/init.d/$NAME 
for i in `echo "$PATH" | tr ':' '\n'` ; do
	if [ -f $i/$NAME ] ; then
		exists=1
		break
	fi
done

#for i in `echo "$PATH" | tr ':' '\n'` ; do
#	if [ -f $i/$NAME ] ; then
		exists=1
#		break
#fi
#done 
  stty stop undef && stty start undef
  [ -d "${base}" ] && cd "${base}"
  su -c "screen -ls | grep -sq "\.${srnname}[[:space:]]" " ${user} || su -c "screen -dm -S ${srnname} 2>&1 1>/dev/null" ${user} | tee -a "$logfile" >&2
  # this works for the screen command, but starting rtorrent below adopts screen session gid
  # even if it is not the screen session we started (e.g. running under an undesirable gid
  #su -c "screen -ls | grep -sq "\.${srnname}[[:space:]]" " ${user} || su -c "sg \"$group\" -c \"screen -fn -dm -S ${srnname} 2>&1 1>/dev/null\"" ${user} | tee -a "$logfile" >&2
  su -c "screen -S "${srnname}" -X screen rtorrent ${options} 2>&1 1>/dev/null" ${user} | tee -a "$logfile" >&2
  
  if [ -e /root/.rtorrent/rpc.socket ] || [ -e /root/.rtorrent/rtorrent.lock ] ; then
	echo "."
	echo "rtorrent has not been properly stop."
	echo "Deleting locked files ..."
	rm -rf /root/.rtorrent/rpc.socket
	rm -rf /root/.rtorrent/rtorrent.lock
	echo -n "Done"
  fi
  if [ -e /root/.rtorrent/rpc.socket ] || [ -e /root/.rtorrent/rtorrent.lock ] ; then
        echo "."
  	echo -n "Locked files not deleted, please check .."
  fi
  stty stop undef && stty start undef
  [ -d "${base}" ] && cd "${base}"
  # su -c "screen -ls | grep -sq "\.${srnname}[[:space:]]" " ${user} || su -c "screen -dm -S ${srnname} 2>&1 1>/dev/null" ${user} | tee -a "$logfile" >&2
  # this works for the screen command, but starting rtorrent below adopts screen session gid
  # even if it is not the screen session we started (e.g. running under an undesirable gid
  # su -c "screen -ls | grep -sq "\.${srnname}[[:space:]]" " ${user} || su -c "sg \"$group\" -c \"screen -fn -dm -S ${srnname} 2>&1 1>/dev/null\"" ${user} | tee -a "$logfile" >&2
  # su -c "screen -S "${srnname}" -X screen rtorrent ${options} 2>&1 1>/dev/null" ${user} | tee -a "$logfile" >&2
  su -c "screen -d -m rtorrent ${options} 2>&1 1>/dev/null" ${user} | tee -a "$logfile" 

Then you should be able to use S99rtorrent with the arguments start|stop|restart. If you are logged on you NAS you can use the command screen -r to observe the rtorrent process. To quit screen use crtl-a-d. If something goes wrong have a look in the /root/rtorrentInit.log logfile. Don't forget to backup /opt/etc/init.d/S99rtorrent, because it will be overwritten by installing a new version of rtorrent. If rtorrent doesn't start, check if the following files exist: /root/.rtorrent/rpc.socket and /root/.rtorrent/rtorrent.lock. If they do, then delete them.

Warning: nano does an automatic word wrap: 1 long line of code may become 2 lines. Take care when editing the file.

As long rtorrent is running (even without downloading/seeding, the HDDs won't go in hibernate mode.

Starting it all

Launch rTorrent (maybe you need to reboot your diskstation to take in account the new rtorrent version, since a process can already be running; the Synology download center is also using rtorrent):

/opt/etc/init.d/S99rtorrent start

If you want to see rtorrent later on, you can just login to your diskstation and enter

screen -r

You can then quit screen by hitting crtl-a-d. If nothing appended, try to launch manually the command rtorrent. If you get the following error message "Fault occured while inserting xmlrpc call", then you have installed the wrong version of xmlrpc-c (Go back to the install the needed packages section)

Now you just need to start lighttpd.

/opt/etc/init.d/S80lighttpd start

Using it

If there where no errors, try to access wTorrent. You can reach it under the following url: http://diskstation:8081/lighttpd/wtorrent (or maybe http://diskstation:8081/wtorrent for oldest versions).

You'll first need to create a user/password on the following page: http://diskstation:8081/wtorrent/install.php If you get the message "wTorrent has already been configured", delete the file /opt/share/www/lighttpd/wtorrent/db/database.db . If no errors, delete/rename install.php.


Using wTorrent should be pretty self-explanatory. RTorrent itself is a little bit more complicated, but it's explained pretty good here by the programmer: RTorrent User Guide.

References

- http://libtorrent.rakshasa.no/wiki/RTorrentXMLRPCGuide

Personal tools
Community Resources