Results 1 to 15 of 44

Thread: rTorrent and libTorrent

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Cool to hear rtorrent has been packaged!

    Any chance the DHT patch could be included in the package?
    See: http://tk.ttdpatch.net/~jdrexler/dht/
    This will give trackerless torrents functionality.

    thanks,
    Pim.

  2. #2
    Join Date
    Feb 2007
    Location
    Moscow, Russia
    Posts
    3,805
    here is updated version of S99rtorrent:

    It is a little simplified, so that is it uses only one configuration file and only one line with options. Now it conforms to /bin/sh sintaxis and works reliably during startup.

    UPDATE 1/2008: I keep this script for historic reference only, as current version of S99rtorrent included in the optware package has even better S99rtorrent. However, the microhowto below applies also to a new standard version.

    PHP Code:
    #! /bin/sh

    # This script depends on screen.
    # For the stop function to work, you must set an
    # explicit session directory using absolute paths in your rtorrent.rc.
    # If you typically just start rtorrent with just "rtorrent" on the
    # command line, all you need to change is the "user" option.
    # Attach to the screen session as your user with
    # "screen -dr rtorrent". Change "rtorrent" with srnname option.
    # See http://libtorrent.rakshasa.no/wiki/RTorrentCommonTasks

    # Do not proceed unless some apps are available.

    test -/opt/bin/screen || exit 0
    test 
    -/opt/bin/su --/bin/su || exit 0

    #######################
    ##Start Configuration##
    #######################
    # You can specify your configuration in a different file
    # (so that it is saved with upgrades, saved in your home directory,
    # or whateve reason you want to)
    # by commenting out/deleting the configuration lines and placing them
    # in a text file (say /home/user/.rtorrent.init.conf) exactly as you would
    # have written them here (you can leave the comments if you desire
    # and then uncommenting the following line correcting the path/filename
    # for the one you used. note the space after the ".".
    # . /etc/rtorrent.init.conf


    #Do not put a space on either side of the equal signs e.g.
    # user = user
    # will not work
    # system user to run as (can only use one)
    # Add this user to /etc/passwd
    user="p2p"

    # the full path to the filename where you store your rtorrent configuration
    # must keep parentheses around the entire statement, quotations around each config file
    #config="/home/${user}/.rtorrent.rc"
    config="/opt/home/${user}/.rtorrent.rc"
    #config="/opt/etc/rtorrent.conf"

    # Examples:
    # config="/home/user/.rtorrent.rc"

    # set of options to run with each instance
    # if no special options, specify with: ""

    # if rtorrent is started without options it will read it's config from ~/.rtorrent.rc
    options=""

    # Examples:
    # starts one instance, sourcing both .rtorrent.rc and .rtorrent2.rc
    # options="-o import=~/.rtorrent2.rc"
    # starts two instances, ignoring .rtorrent.rc for both, and using
    # .rtorrent2.rc for the first, and .rtorrent3.rc for the second
    # we do not check for valid options
    # options="-n -o import=~/.rtorrent2.rc" "-n -o import=~/rtorrent3.rc"
    #options="-n -o import=/opt/etc/rtorrent.conf"

    # default directory for screen, needs to be an absolute path
    #base="/home/${user}"
    base="/opt/home/torrent"

    # name of screen session
    srnname="rtorrent"
    #######################
    ###END CONFIGURATION###
    #######################
    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 || (logger -t rtorrent "no daemon" && exit 0)

    checkcnfg() {
      if ! [ -
    "${config}] ; then
        logger 
    -t rtorrent "cannot find readable config ${config}. check that it is there and permissions are appropriate"
        
    exit 3
      fi
      session
    =$(awk '/^[[:space:]]*session[[:space:]]*=[[:space:]]*/{print($3)}' "${config}")
      if ! [ -
    "${session}] ; then
        logger 
    -t rtorrent "cannot find readable session directory ${session} from config ${config}. check permissions"
        
    exit 3
      fi
    }

    d_start() {
      [ -
    "${base}] && cd "${base}"
      
    stty stop undef && stty start undef
      su 
    -"screen -ls | grep ".${srnname}[[:space:]]" > /dev/null" ${user} || su -"screen -dm -S ${srnname}${user}
      
    sleep 3
      su 
    -"screen -S "${srnname}" -X screen rtorrent ${options}${user}
      
    su -"screen -S "${srnname}" -p 0 -X kill" ${user}
      
    logger -t rtorrent "started."
    }

    d_stop() {
      
    session=$(awk '/^[[:space:]]*session[[:space:]]*=[[:space:]]*/{print($3)}' "${config}")
      
    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
      
    grep rtorrent /proc/${pid}/cmdline > /dev/null && kill -s INT ${pid}
      
    sleep 6s
      logger 
    -t rtorrent "stopped."
    }

    checkcnfg

    case "$1" in
      start
    )
            echo -
    "Starting $DESC$NAME"
            
    d_start
            
    echo "."
            
    ;;
      
    stop)
            echo -
    "Stopping $DESC$NAME"
            
    d_stop
            
    echo "."
            
    ;;
      
    restart|force-reload)
            echo -
    "Restarting $DESC$NAME"
            
    d_stop
            sleep 1
            d_start
            
    echo "."
            
    ;;
      *)
            echo 
    "Usage: $SCRIPTNAME {start|stop|restart|force-reload}" >&2
            
    exit 1
            
    ;;
    esac

    exit 
    Here is a short instruction how to use rtorrent by user another than root.

    1) Create user:
    PHP Code:
    adduser p2p 
    If necessary:
    PHP Code:
    ipkg install adduser 
    2) Add the following lines to ~/.profile:
    PHP Code:
    alias rt='su -c "screen -r" p2p'
    chmod a+rw `tty`
    stty start undef
    stty stop undef 
    tty is unfortunately also a part of coreutils However,. Oleg included it already in the next version of his fw (after preview 8.8)

    Don't forget to save changes:
    PHP Code:
    flashfs save && flashfs commit && flashfs enable && reboot 
    3) This utility requires to have installed: screen
    PHP Code:
    ipkg install screen 
    and su. With su current situation is more complicated. The latest Oleg's firmware (1.9.2.7-8.7) includes /bin/su , so nothing have to be done. However if you have earlier version then su has to be installed. It is a part of adduser and coreutils packages.

    4) Create configuration file in the p2p's user home directory ( ~/.rtorrent.rc ) based on /opt/home/rtorrent.conf

    5) set correct ownership and permissions on the rtorrent working directories depending on which directories are written in ~/.rtorrent.rc file
    PHP Code:
    chown -R p2p:p2p /opt/share/torrent/work
    chown 
    -R p2p:p2p /opt/share/torrent/session
    chown 
    -R p2p:p2p /opt/share/torrent/dl 
    6) when you want to attach to it use:
    PHP Code:
    rt 
    P.S. This script has 1 small bug/feature. An extra screen window with /bin/sh is started which can be afterwards exited manually. Up to now nobody knows how to eliminate it
    Last edited by al37919; 13-10-2008 at 16:21.

  3. #3
    Quote Originally Posted by al37919 View Post
    P.S. This script has 1 small bug/feature. An extra screen window with /bin/sh is started which can be afterwards exited manually. Up to now nobody knows how to eliminate it
    Hey, al37919, when you do "screen -S rtorrent -X screen rtorrent" what you're doing is creating a new screen window window with the rtorrent program running on it. There is window #0 and then you are creating window #1 with rtorrent attached. If you want to get rid of that extra window (window #0), you can do two things:

    1) Send an stuff command to screen, with rtorrent and the carriage return code (Control-M). With -p 0 you select the window #0 and stuff sends the parameter string to that window:

    Code:
    screen -S rtorrent -p 0 -X stuff 'rtorrent^M'
    2) Send the kill command to the same window:

    Code:
    screen -S rtorrent -p 0 -X kill
    The second command can also be used to kill the window after rtorrent exits, if you want to.

  4. #4
    Join Date
    Feb 2007
    Location
    Moscow, Russia
    Posts
    3,805
    Hi! Thanks for the advice, I've somehow missed this message. Now I tested both possibilities:

    Thing #1 unfortunately is not completely effective. Using it we really have only single window #0 in the session, however the junk /bin/sh process is still sitting in the 'ps aux' output. Killing of this /bin/sh naturally kills both rtorrent and screen.

    Thing #2 seems to solve the issue. If we add it at the end of the d_start() function we get rtorrent started without annoying process in the memory. Exiting of the rtorrent results in termination of teh screen session.

    Thanks a lot again,
    al
    Last edited by al37919; 13-10-2008 at 16:19.

Posting Permissions

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