Results 1 to 15 of 102

Thread: [How to] rtorrent & ntorrent

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1

    [How to] rtorrent & ntorrent

    I figured I'd try to write a brief how to on getting the rtorrent/ntorrent working together since I've went through it recently in desperation (my Transmission is acting up and downloading really slow, with only half a dozen peers per torrent and no obvious problems to fix).

    This is meant for those who wish to run an alternative BT (rtorrent) and do not mind using a client side interface (ntorrent) on their desktop to manage their torrents.

    ntorrent is a Java based application and will work on any platform supporting Java >= 1.6. Go to its page and download the binary package to your desktop, it's in the featured downloads (bz2 file and any language addition you need).

    Anyways, this might not be exactly step-by-step since I'm recollecting my journey and I might miss a step so please pitch in with your comments.

    Oh, if you mess up your router I am not responsible - you have been warned!

    I will assume that everyone has a similar setup, WL500gP, /opt and oleg's firmware/feeds.

    First of all make sure you got everything up to date:

    Code:
    ipkg update
    ipkg upgrade
    Then we need to grab rtorrent, it will also install libtorrent and bunch of other things (xmlrpc etc) but no worries you need those as well

    Code:
    ipkg install rtorrent
    We'll need to run apache or lighttpd to have scgi, so let's install the later:

    Code:
    ipkg install lighttpd
    Also, we need screen:

    Code:
    ipkg install screen
    ...and bash

    Code:
    ipkg install bash
    Now we are ready to do some configurating, first lighttpd, the config file for it is in /opt/etc/lighttpd/lighttpd.conf so edit it:

    Code:
    vi /opt/etc/lighttpd/lighttpd.conf
    I have kept most things default, you may change the port from default 8081 to something else if you like.
    I didn't, what I added was mod_scgi in the server.modules list (I added around the end, you can add anywhere as long as it's not commented):

    Code:
    #                               "mod_rrdtool",
                                    "mod_scgi",
                                    "mod_accesslog" )
    At the very end of the file I've added the following:

    Code:
    scgi.server = (                                                            
            "/RPC2" =>                                                         
                    ( "127.0.0.1" =>                                             
                            (                                                    
                                    "socket" => "/opt/var/run/rpc.socket",       
                                    "check-local" => "disable",                  
                                    "disable-time" => 0,  # don't disable scgi if connection fails
                            )                                                    
                    )                                                            
            )
    This will enable passing the socket connection from rtorrent via lighttpd to our remote ntorrent client via http:// protocol.

    Save and exit the file.

    Let's make rtorrent config file next, I will use a non default location for it (it usually sits in your home dir as .rtorrent.rc but I want it on my mounted drive):

    Code:
    vi /opt/etc/rtorrent.conf
    And these are some of the settings, you can adjust more settings by reading the rtorrent manpage

    Code:
    scgi_local = /opt/var/run/rpc.socket
    session = /opt/share/torrent/work
    port_range = 10000-11000
    directory = /opt/share/torrent/dl
    check_hash = yes
    encryption = prefer_plaintext
    stop_on_ratio = 100
    upload_rate = 50
    max_uploads = 5
    I have used ports 10000-11000 for it, but you can use any port range you like. Remember that you will have to open these ports in your firewall, so...

    Code:
    vi /usr/local/sbin/post-firewall
    This is what you should have, at least:

    Code:
    #!/bin/sh
    
    ## FIREWALL
    ## set default policy
    iptables -P INPUT DROP
    ## deny ftp access from WAN
    iptables -I INPUT 1 -p tcp -i "$1" --syn --dport 21 -j DROP
    ## Allow access to various router services from WAN
    ## open 10000-11000 for rtorrent
    for P in 10000:11000; do
      iptables -I INPUT 1 -p tcp --syn -i "$1" --dport $P -j ACCEPT
    done
    You might wanna change your pre-shutdown as well, I used the one wirespot posted (thanks!).

    Code:
    vi /usr/local/sbin/pre-shutdown
    ...and add the following:

    Code:
    #!/bin/sh
    # This one is simple. I send signal INT to rtorrent
    # to tell it to do a graceful shutdown that will make
    # it save its hashes and full status. (You need to
    # enable sessions with session=dir in rtorrent.rc
    # for this to work!):
    /bin/kill -INT $(/bin/pidof rtorrent) &
    # Then I wait for 10 seconds to be sure it died
    # gracefully. The rtorrent docs say it dies in 5,
    # I just wanna make extra sure.
    /bin/sleep 10
    Since we made the change to flashfs this needs to "stick" after reboot so:

    Code:
    flashfs save && flashfs commit

  2. #2

    (continued...)

    Next let's look at the script that starts rtorrent:

    Code:
    vi /opt/etc/init.d/S99rtorrent
    I had to change it because I did not use su, my user already has root privileges so I'm pasting the entire script without comments, so replace what you have with code below:

    Code:
    #!/opt/bin/bash 
    # Do not proceed unless some apps are available.
    test -x /opt/bin/screen || exit 0
     
    ##Start Configuration##
    
    # the full path to the filename where you store your rtorrent configuration
    config=("/opt/etc/rtorrent.conf")
     
    # set of options to run with each instance, separated by a new line
    options=("-n -o import=/opt/etc/rtorrent.conf")
    
    # default directory for screen, needs to be an absolute path                           
    base="/opt/share/torrent"                                                              
                                                                                           
    # name of screen session                                                               
    srnname="rtorrent"                                                                     
    #######################                                                                                                                                
    PATH=/opt/local/bin:/opt/sbin:/opt/bin:/sbin:/bin:/usr/sbin:/usr/bin                   
    DESC="rtorrent"                                                                        
    NAME=rtorrent                                                              
    DAEMON=/opt/bin/$NAME                                                                  
    SCRIPTNAME=/opt/etc/init.d/S99rtorrent                                                 
                                                                                           
    # Gracefully exit if the package has been removed.                                     
    test -x $DAEMON || exit 0                                                              
                                                                                           
    checkcnfg() {                                                                          
      for (( i=0 ; i < ${#config[@]} ;  i++ )) ; do                                        
            if ! [ -r "${config[i]}" ] ; then                                              
                    echo "cannot find readable config ${config[i]}. check that it is there and permissions are appropriate">&2
                    exit 3                                                                                                    
            fi                                                                             
            session=$(cat "${config[i]}" | grep "^[[:space:]]*session" | sed "s/^[[:space:]]*session[[:space:]]*=[[:space:]]*//")
            if ! [ -d "${session}" ] ; then                                                                                      
                    echo "cannot find readable session directory ${session} from config ${config[i]}. check permissions">&2   
                    exit 3                                                                                                       
            fi                                                                                                                
      done                                                                                                                       
    }                                                                                                                            
                                                                                                                                 
    d_start() {                                                                                                                  
    logger "Starting."                                                                                                           
      [ -d "${base}" ] && cd "${base}"                                                                                           
      stty stop undef && stty start undef                                                                                        
      screen -ls | grep .${srnname}[[:space:]] > /dev/null || screen -dm -S ${srnname}                                           
      for (( i=0 ; i < ${#options[@]} ; i++ )) ;  do                                                                             
        sleep 3                                                                                                                  
        screen -S ${srnname} -X screen rtorrent ${options[i]}                                                                    
      done                                                                                                                       
    }            
    d_stop() {                                                                                                                   
      for (( i=0 ; i < ${#config[@]} ; i++ )) ; do                                                                            
            session=$(cat "${config[i]}" | grep "^[[:space:]]*session" | sed "s/^[[:space:]]*session[[:space:]]*=[[:space:]]*//")
            pid=$(cat ${session}/rtorrent.lock | awk -F: '{print($2)}' | sed "s/[^0-9]//g")                                      
            # make sure the pid doesn't belong to another process                                                                
            # skip the pid otherwise                                                                                             
            if ps | grep ${pid}.*rtorrent > /dev/null ; then                                                                     
                    kill -s INT ${pid}                                                                                           
            fi                                                                                                                   
      done                                                                                                                       
    }                                                                                                                         
                                                                                                                              
    checkcnfg                                                                                                                    
                                                                                                                                 
    case "$1" in                                                                                                                 
      start)                                                                                                                     
            echo -n "Starting $DESC: $NAME"                                                                                      
            d_start                                                                                                              
            echo "."                                                                                                             
            ;;                                                                                                                   
      stop)                                                                                                                      
            echo -n "Stopping $DESC: $NAME"                                                                                      
            d_stop                                                                                                               
            echo "."                                                                                                             
            ;;                                                                                                                   
      restart|force-reload)                                                                                                      
            echo -n "Restarting $DESC: $NAME"                                                                                    
            d_stop                                                                                                               
            sleep 1                                                                                                              
            d_start                                                                                                              
            echo "."                                                                                                             
            ;;                                                                                                                   
      *)                                                                                                                         
            echo "Usage: $SCRIPTNAME {start|stop|restart|force-reload}" >&2                                                      
            exit 1                                                                                                               
            ;;                                                                                                                   
    esac                                                                                                                         
                                                                                                                                 
    exit 0
    Hmm, so I guess that's it, let's reboot to make sure everything starts on its own, firewall applies new rules etc...

  3. #3

    (continued...)

    After reboot, do ps and you should see lighttpd running as well as screen with your rtorrent attached to it including the -n -o import=...rtorrent.conf.

    Now, go to your browser and connect to the lighttpd:

    Code:
    http://routerIP:8081
    You should see "lighttpd server is running." Excellent!

    Next connect to the socket interface:

    Code:
    http://routerIP:8081/RPC2
    You should see an empty screen (as in white...) but that's good. Otherwise if you get 500 Server error, then something is wrong. Either rtorrent isn't running, or lighttpd isn't passing RPC through the socket. Hard to say, you will have to troubleshoot it...

    We are ready to connect to our rtorrent now. Unpack the downloaded ntorrent binary somewhere (C:\Program Files\ntorrent, /Applications/ntorrent, /opt/ntorrent ...) and run it. The *ix users can use .sh file included, Winblows users should double-click on the .jar file.

    You will see a Profiles dialogue, select http from the protocol drop-down.

    Under host enter the IP of your router.

    Connection port is 8081 (default for lighttpd or whatever else you set it to).

    Mountpoint is /RPC2 (remember that's what we told lighttpd to use as an interface between the rtorrent socket and the Web).

    Username is your user on the router, and Password is its password.

    Tick "Remember Password" and click "Save profile".

    In a moment you should be connected. Look at the bottom of the ntorrent window, there are some numbers there. You should see the Port: 10000-11000 (range we have set earlier), and your Ping: 2 sec or so...zomg it worked, you lucky, you !

    So, "File/Add torrent" and off you go, it's pretty simple to use - you'll figure it out on your own.

    Happy Holidays!

    P.S. This is how I've done it (to best of my knowledge/recollection) so if you run into trouble you are on your own...
    Last edited by mancub; 23-12-2007 at 20:49.

  4. #4
    Hello,

    What can i say it is relay great tutorial for rtorret and ntorrent.

    I LIKE IT

    and yeah UPLOAD IS WORKING NORMAL now. With transmission i have big problems 0 upload 200 download :S so my ratio was f...... up

    THX m8
    Last edited by polde; 24-12-2007 at 10:37.

  5. #5
    Join Date
    Feb 2007
    Location
    Moscow, Russia
    Posts
    3,805
    Why not use:
    PHP Code:
    iptables -I INPUT 1 -p tcp --syn -"$1" --dport 10000:11000 -j ACCEPT 
    instead of:
    PHP Code:
    for P in 10000:11000; do
      
    iptables -I INPUT 1 -p tcp --syn -"$1" --dport $P -j ACCEPT
    done 
    Finally, are you sure that rtorrent needs that much ports to be opened? I guess the default value is something like 4-10 ports.

    Actually I suggest the following rework of the minimalistic post-firewall file:

    PHP Code:
    #! /bin/sh

    ## FIREWALL
    ## set default policy
    iptables -P INPUT DROP
    # remove last default rule
    iptables -D INPUT -j DROP

    ## Allow access to various router services from WAN
    ## open 10000-11000 for rtorrent
    iptables -A INPUT -p tcp --syn -"$1" --dport 10000:11000 -j ACCEPT 
    This allows painless addition of the new rules in the end of the INPUT chain which is generally more correct way in comparison with inserting them in the beginning.

    However, strictly speaking this method implies a requirement to set: Internet Firewall - Basic Config - Logged packets type: NONE
    Last edited by al37919; 24-12-2007 at 12:48.

  6. #6
    Hello,

    Default configuration is following:

    PHP Code:
    # Port range to use for listening.
    port_range 51777-51780 
    i use this port range and this iptables WHY? I have set ssh and other ports to open state.

    example:

    PHP Code:
    for P in 22 8008 10000:11000; do
      
    iptables -I INPUT 1 -p tcp --syn -"$1" --dport $P -j ACCEPT
    done 
    Some one know what is this seating

    PHP Code:
    # Set whetever the client should try to connect to UDP trackers.
    use_udp_trackers yes 
    Last edited by polde; 24-12-2007 at 12:48.

  7. #7
    Is the stop_on_ratio setting working for you?

    In my /opt/etc/rtorrent.conf i have the line stop_on_ratio = 120 but this morning i recognized that there was a torrent with a ratio over 2,2 and still seeding?

    So it seems that this command was not recognized by the client.

    Edit:
    The stop_on_ration command like it is showed all pver the Thread is simply wrong. It has to be combined with a scheduler Task, like it is explained in the sample rtorrent.conf.
    Last edited by darkside40; 30-07-2008 at 23:19.

  8. #8
    Can someone please just post a WORKING guide from start to end!

    The existing guide must be OUT-OF-DATE, because I(and others) keep getting Time-out issue!

    I tried to sum up what everyone has written in this thread, and sofar i got nowhere.

    I'm getting annoyed in using Enhanced Torrent, because its SO buggy!

    Please help, thanks

    /Morten

  9. #9
    Quote Originally Posted by msj33 View Post
    Everyone says, that its a firewall issue - but where? I opened both ports in IPTABLES and my Modem/router.

    My ASUS is NOT setup like a router - Only as an Access point - Don't know if this has any effect to the issue.
    Are you sure you also forwarded ports on internal router to you access point. Opening port on your router will not work , for other devices behind router.

  10. #10
    cupacup> Yes I portforwarded port 10000-11000 to 192.168.1.10 which is my ASUS - Then furthermore did the IPTABLES changes as suggested in the guide.

    Can someone working post:
    Guide

    or

    Firmware version
    Rtorrent/Libtorrent versions
    etc.

    Thanks

    /Morten

  11. #11
    Whooooo.........somehow i got it working!!?!?!?

    I don't know how, but i would guess, that it is cause by a update.

    I did a "ipkg update" and afterwardx a "ipkg upgrade" and then did gouryella's setup again and everything is working fine now - no longer timeout issue.

    Thanks goes out to the ones who tried to help me out

    /Morten

Similar Threads

  1. Replies: 28
    Last Post: 02-06-2013, 20:58
  2. Ipkg rtorrent Packet gesucht
    By FastJack in forum German Discussion - Deutsch (DE)
    Replies: 1
    Last Post: 23-10-2007, 17:37
  3. older rtorrent version
    By FastJack in forum WL-500gP Q&A
    Replies: 1
    Last Post: 23-10-2007, 09:40
  4. [How To] Oleg Firmware installeren.
    By Dragonar in forum Dutch Discussion - Nederlands
    Replies: 7
    Last Post: 08-05-2007, 18:34
  5. [HOW TO] Timeouts beim Laden von bestimmten Seiten beheben - MTU Problem
    By modnet25 in forum German Discussion - Deutsch (DE)
    Replies: 3
    Last Post: 03-09-2006, 10:55

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •