Page 2 of 3 FirstFirst 123 LastLast
Results 16 to 30 of 44

Thread: rTorrent and libTorrent

  1. #16
    Join Date
    Feb 2007
    Location
    Moscow, Russia
    Posts
    3,805
    There is a script which can be used to run rTorrent on system startup suggested here: http://libtorrent.rakshasa.no/wiki/RTorrentCommonTasks

    So, I have slightly modified it and put in /opt/etc/init.d/S99rtorrent
    It starts rtorrent as user p2p with configuration file located in /opt/etc/rtorrent.conf and working directory /opt/share/torrent

    PHP Code:
    # !/bin/sh
    #############
    ###<Notes>###
    #############
    # 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.
    ##############
    ###</Notes>###
    ##############


    #######################
    ##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)
    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/etc/rtorrent.conf")
    # Examples:
    # config=("/home/user/.rtorrent.rc")
    # config=("/home/user/.rtorrent.rc" "/mnt/some/drive/.rtorrent2.rc")
    # config=("/home/user/.rtorrent.rc"
    # "/mnt/some/drive/.rtorrent2.rc"
    # "/mnt/another/drive/.rtorrent3.rc")

    # set of options to run with each instance, separated by a new line
    # must keep parentheses around the entire statement
    #if no special options, specify with: ""
    options=("-n -o import=/opt/etc/rtorrent.conf")
    # 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")

    # default directory for screen, needs to be an absolute path
    #base="/home/${user}"
    base="/opt/share/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 || exit 0

    checkcnfg
    () {
      for (( 
    i=< ${#config[@]} ;  i++ )) ; do
            
    if ! [ -"${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 ! [ -
    "${session}] ; then
                    
    echo "cannot find readable session directory ${session} from config ${config[i]}. check permissions">&2
                    
    exit 3
            fi
      done
    }

    d_start() {
    logger "Starting."
      
    [ -"${base}] && cd "${base}"
      
    stty stop undef && stty start undef
      su 
    -"screen -ls | grep "\.${srnname}[[:space:]]" > /dev/null" ${user} || su -"screen -dm -S ${srnname}${user}
      for (( 
    i=< ${#options[@]} ; i++ )) ;  do
        
    sleep 3
        su 
    -"screen -S "${srnname}" -X screen rtorrent ${options[i]}${user}
      
    done
    }

    d_stop() {
      for (( 
    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 -
    "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 

  2. #17
    Join Date
    Jun 2005
    Location
    Slovenia
    Posts
    736
    Included into optware with http://trac.nslu2-linux.org/optware/changeset/6061

    Please report any problems with script here!

  3. #18
    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.

  4. #19
    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.

  5. #20

    What about "ps -A" command's option in the S99rtorrent script?

    Please accept my apologies for my English...

    My ps command hasn't any options.

    [admin@suleyma root]$ ps -?
    ps: illegal option -- ?
    BusyBox v1.1.3 (2007.01.01-14:37+0000) multi-call binary

    Usage: ps

  6. #21
    That's the default ps that comes with the firmware, and is embedded in the flash. Install the procps package (ipkg install procps) to get a better ps.

    If S99rtorrent uses ps with arguments it's a bit of an oversight. It should test what kind of ps it's dealing with. If the advanced ps becomes a requirement, the rtorrent package would have to require (or at least recommend) the procps package. Which would be a bit silly.

    al37919, you don't need ps -A for that if block in your script. You can do this instead:

    Code:
    grep rtorrent /proc/${pid}/cmdline && \
    kill -s INT ${pid}

  7. #22
    I've installed procps.

    There is a mention of procps by wengi:http://wl500g.info/showthread.php?t=...unslung&page=4

    Cron must be in the process list (ps) after a reboot.
    Remark: If you installed procps you should execute:
    Êîä: ps axf
    Thanks for your quick response.

  8. #23
    It's just that I've had my WL-500g for quite a while now and so far I've haven't felt the need for the advanced ps. Installing it just for a ps -A, which can be accomplished in a more efficient manner anyway, is a bit overkill.

  9. #24
    I think I quite agree with you.
    Look below where a short instruction how to use rtorrent by user another than root.
    What do you think about:
    ipkg install coreutils
    I've done it.

  10. #25
    Join Date
    Feb 2007
    Location
    Moscow, Russia
    Posts
    3,805
    Thanks for the comemnts. I changed the script posted above so that now it explicitly uses busybox's /bin/ps. So, there is no need now to install procps package, other than ps in it is much nicer than the standard one

    I agree that coreutils is a big package, that should be installed here only to be able to use su. However, su is required to be able to start rtorrent as non-root user, and it is not included in our version of busybox. May be we can ask Oleg to include it in the future releases...

  11. #26
    You dont't need install coreutils for su.
    It's enough to install adduser.
    I've removed coreutils now and reinstall adduser - su is working (executing).

    It seems: ipkg -force-reinstall install adduser

    To be on the safe side, after executed ipkg remove coreutils, I've reinstalled all installed packages by one line awk script taken somewhere from the Forum:
    /usr/bin/awk '/^Package:/{system("/opt/bin/ipkg install -force-reinstall -force-defaults " $2)}' /opt/lib/ipkg/status
    But now I have next records in my /opt/var/log/messages:
    Code:
    Nov  2 16:00:40 admin: Starting.
    Nov  2 16:00:40 su: + none admin:p2p
    Nov  2 16:00:40 su: + none admin:p2p
    Nov  2 16:00:43 su: + none admin:p2p
    I think that is result executing this code:
    Code:
    for (( i=0 ; i < ${#options[@]} ; i++ )) ;  do
        sleep 3
        su -c "screen -S "${srnname}" -X screen rtorrent ${options[i]}" ${user}
      done
    But the same was before install coreutils...

  12. #27
    Anyone tried nTorrent accessing rTorrent on a Oleg Asus router ?

    Would be pretty nice if it worked

    Its not a web-gui, but still...

    Edit:

    Also found wTorrent - web-gui for rTorrent, anyone tried that ?
    Last edited by Pulver; 25-11-2007 at 19:01.

  13. #28
    I plan to test it as soon as possible. Of course, it depends on whether Oleg compiled rtorrent with --with-xmlrpc-c. Sure, I can compile my own and still test it, but for mass use it will still have to have it.

    The entire XMLRPC support thingy is very interesting and I'm glad there are finally applications using it. Controlling rtorrent remotely would be the final bit of goodness.

    Some more info:
    http://rakshasa.no/pipermail/libtorr...ay/001154.html

    LE: sorry, no XMLRPC support compiled in.
    Last edited by wirespot; 25-11-2007 at 22:49.

  14. #29
    Join Date
    Feb 2007
    Location
    Moscow, Russia
    Posts
    3,805
    last version in repository has been compiled with xmlrpc support

  15. #30
    Ah, sorry then, I must be late upgrading.

    BTW, don't try setting the scgi_port option with older rtorrent builds, you'll crash them.
    Last edited by wirespot; 25-11-2007 at 22:59.

Page 2 of 3 FirstFirst 123 LastLast

Posting Permissions

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