Gentoo Forums
Gentoo Forums
Gentoo Forums
Quick Search: in
rtorrent daemon
View unanswered posts
View posts from last 24 hours

Goto page 1, 2  Next  
Reply to topic    Gentoo Forums Forum Index Documentation, Tips & Tricks
View previous topic :: View next topic  
Author Message
roog
Tux's lil' helper
Tux's lil' helper


Joined: 01 Aug 2004
Posts: 100

PostPosted: Tue Oct 16, 2007 5:04 pm    Post subject: rtorrent daemon Reply with quote

Hi All,

rtorrent is a nice and fast text-based ncurses BitTorrent client and is ideal for use with dtach (or screen). I wanted to run rtorrent as a daemon on my server allowing it to:

- start automatically at boot
- connect to using ssh
- watch for torrents in a specified directory
- move completed torrents to a different directory

To do this, make sure you have the latest rtorrent (0.7.8 at the time of this writing, currently keyworded ~arch in portage) and dtach installed. Copy-paste the following code into a file called /etc/init.d/rtorrent:

Code:

#!/sbin/runscript
# Copyright 2007 Rogier Koppejan
# Distributed under the terms of the GNU General Public License v2

depend() {
        use net
}

start() {
        ebegin "Starting rtorrent"
        start-stop-daemon --start --chuid $USER \
            --env TERM="xterm" \
            --env HOME="/home/$USER" \
            --exec $DTACH -- -n $SOCKET $RTORRENT
        eend $?
}

stop() {
        ebegin "Stopping rtorrent"
        start-stop-daemon --stop --signal 2 --name rtorrent
        eend $?
}


The configuration options go into /etc/conf.d/rtorrent, adjust the options to your personal needs:

Code:

# /etc/conf.d/rtorrent: config file for /etc/init.d/rtorrent

# Options to pass to the rtorrent daemon.

# The username/uid to start rtorrent with
USER="username"

# Path to the dtach binary (needs to be absolute path)
DTACH="/usr/bin/dtach"

# The socket for the rtorrent
SOCKET="/tmp/rtorrent.dtach"

# Path to the rtorrent binary (needs to be absolute path)
RTORRENT="/usr/bin/rtorrent"


Now create and configure your ~/.rtorrent.rc. A sample can be found here, here's mine:

Code:

# Maximum and minimum number of peers to connect to per torrent.
min_peers = 20
max_peers = 200

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

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

# Session directory where rtorrent will save torrent info.
session = ~/.rtorrent.session

# Default directory to save the downloaded torrents.
directory = ~/Download/torrents/active/

# Watch a directory for new torrents and stop those that
# have been deleted.
schedule = watch_directory,5,5,load_start=~/Download/torrents/active/*.torrent
schedule = untied_directory,5,5,remove_untied=

# When the torrent finishes, remove torrent and move downloaded
# files to ~/Download/torrents/finished/.
on_finished = rm_torrent,"execute=rm,$d.get_tied_to_file="
on_finished = move_complete,"execute=mv,-u,$d.get_base_path=,~/Download/torrents/finished/ ;d.set_directory=~/Download/torrents/finished/"

# Close torrents when diskspace is low.
schedule = low_diskspace,5,60,close_low_diskspace=100M

# Stop torrents when reaching upload ratio in percent,
# when also reaching total upload in bytes, or when
# reaching final upload ratio in percent.
schedule = ratio,60,60,"stop_on_ratio=100"

# Port range to use for listening.
port_range = 6891-6900

# Scheduling upload rates.
schedule = throttle_day,10:00:00,24:00:00,upload_rate=30
schedule = throttle_night,20:00:00,24:00:00,upload_rate=40


Then add rtorrent to de default runlevel, exec as root:

Code:
$ rc-update add rtorrent default


You can attach to rtorrent and view its status executing:

Code:
dtach -a /path/to/socket


or

Code:
dtach -A /path/to/socket rtorrent


Type Ctrl+\ to detach rtorrent again. Finally, I've created the following alias in my ~/.bashrc to make my life easier:

Code:
alias rtorrent='dtach -A /path/to/socket /usr/bin/rtorrent'


This command will connect to rtorrent or restart it in case it died for some reason (which doesn't ever happen as far as I can tell, but just in case).

That's it! You're all set. Torrents can now be uploaded from anywhere to your watch directory (local or remote using scp, ftp, ...) and you can monitor rtorrents status at any time (also local or remote).

Happy downloading!

PS) The daemon script could be enhanced by using pidfiles. However, when I try this with -m --pidfile /path/to/pidfile, the pid of dtach instead of rtorrent is stored. If anyone knows how to solve this, please tell me!

[Edit1]: Added the line --env TERM="xterm" to the init script.
[Edit2]: Included rtorrent.rc info.


Last edited by roog on Thu Nov 08, 2007 8:40 am; edited 7 times in total
Back to top
View user's profile Send private message
nixnut
Bodhisattva
Bodhisattva


Joined: 09 Apr 2004
Posts: 10974
Location: the dutch mountains

PostPosted: Tue Oct 16, 2007 5:23 pm    Post subject: Reply with quote

Moved from Gentoo Chat to Documentation, Tips & Tricks.
_________________
Please add [solved] to the initial post's subject line if you feel your problem is resolved. Help answer the unanswered

talk is cheap. supply exceeds demand
Back to top
View user's profile Send private message
Oak
Apprentice
Apprentice


Joined: 25 Jan 2005
Posts: 239
Location: Sweden

PostPosted: Wed Oct 17, 2007 9:37 pm    Post subject: Reply with quote

Excellent, thank you. Unfortunately I can't help you improving it though. I just wanted to thank you.

:)
_________________
GCC-4.3.3-r1 - march=core2, gentoo-sources-2.6.30-r2 SMP x86_64 @ Core2Duo 2.4GHz, 4GB RAM
Back to top
View user's profile Send private message
roog
Tux's lil' helper
Tux's lil' helper


Joined: 01 Aug 2004
Posts: 100

PostPosted: Thu Oct 18, 2007 10:46 am    Post subject: Reply with quote

I've made a small update to the init-script. During init, TERM is set to linux, so dtach is started with the TERM=linux environment. When you reattach to the rtorrent dtach session after the boot process, TERM is usually set to xterm, and this will result in weird keybinding behaviour. For instance the ALT key seems to be activated continuously and the up/down/left/right-keys can no longer be used for navigating in rtorrent. Look here and here for more info.

In short, the line

Code:
 --env TERM="xterm" \


was added to the startup script. Now everything seems to be fine again.
Back to top
View user's profile Send private message
Oak
Apprentice
Apprentice


Joined: 25 Jan 2005
Posts: 239
Location: Sweden

PostPosted: Thu Oct 18, 2007 12:38 pm    Post subject: Reply with quote

Quote:
For instance the ALT key seems to be activated continuously and the up/down/left/right-keys can no longer be used for navigating in rtorrent.


Thanks for the update!
_________________
GCC-4.3.3-r1 - march=core2, gentoo-sources-2.6.30-r2 SMP x86_64 @ Core2Duo 2.4GHz, 4GB RAM
Back to top
View user's profile Send private message
59729
Apprentice
Apprentice


Joined: 21 Jun 2004
Posts: 279

PostPosted: Sun Nov 25, 2007 10:00 pm    Post subject: Reply with quote

Hmmm I will have a look at this when I get the time, would be cool if it could repair, extract and move the files when they are downloaded to.
Back to top
View user's profile Send private message
toaster.waffle
n00b
n00b


Joined: 25 Oct 2005
Posts: 31
Location: Thunder Bay, ON

PostPosted: Wed May 21, 2008 12:24 am    Post subject: Reply with quote

I'm interested in seeing a daemon using detached screen sessions and with support for multiple instances of rtorrent. Right now I'm just using /etc/conf.d/local.start but would like to see a solution from someone who knows more about how to do things properly than I do.

Good work nonetheless :)



P.S. (for the curious...)
/etc/conf.d/local.start:

# Wipe dead screens.
su - limiteduser -c "exec screen -wipe" &> /dev/null

# Start first instance of rtorrent in screen with different settings than those in ~/.rtorrent.rc
su - limiteduser -c "exec screen -dm rtorrent -n -p 45320-45320 -s ~/Music/.rtorrent-session/ -d ~/Music/ -o download_rate=0,upload_rate=20"

# Start rtorrent with settings from ~/.rtorrent.rc
su - limiteduser -c "exec screen -dmS rtorrent rtorrent"


_________________
$ mkdir matter; cat >matter
matter: cannot create
Back to top
View user's profile Send private message
anxt
Apprentice
Apprentice


Joined: 25 Feb 2003
Posts: 254
Location: Frozen Tundra, Canada

PostPosted: Wed May 21, 2008 7:34 am    Post subject: Reply with quote

Just recently I learned the bash shell (and i think ksh) has a disown builtin. So you can remove a job from list and close shell, no dtach or screen. Probably not relevant but interesting noetheless. I learn a little unix every day.
Back to top
View user's profile Send private message
RaceTM
Apprentice
Apprentice


Joined: 16 Feb 2004
Posts: 281

PostPosted: Wed May 21, 2008 10:13 pm    Post subject: Reply with quote

Is anyone else having an issue with torrents having their hash check fail and thus stop the download? If I restart the daemon it resumes fine, however I haven't been able to successfully get the rtorrent daemon to restart using crontab. It's very frustrating...I tried everything from /etc/init.d/rtorrent restart, to doing a killall rtorrent every hour and /etc/init.d/rtorrent start a minute later. Nothing seems to work. Can anyone make a suggestion?
Back to top
View user's profile Send private message
anxt
Apprentice
Apprentice


Joined: 25 Feb 2003
Posts: 254
Location: Frozen Tundra, Canada

PostPosted: Thu May 29, 2008 7:42 am    Post subject: Reply with quote

perhaps you should look at dmesg for CRC errors? rtorrent has run so well for me, so much i lose a session and realize i shared (gentoo) isos at like 50 to 1 ratio :) you shouldn't get very many hash failures unless you are being fed deliberately bad data. if it checks good on download, it should remain that way.

(or the data on your disk is failing)
Back to top
View user's profile Send private message
lazx888
Tux's lil' helper
Tux's lil' helper


Joined: 13 Sep 2005
Posts: 118

PostPosted: Sat May 31, 2008 4:42 pm    Post subject: Reply with quote

So you download the torrent to an active directory, and when finished, remove the torrent and move the files to a completed directory - no seeding?

Or does schedule = ratio,60,60,"stop_on_ratio=100" determine when the torrent is "finished"??

Great work (if seeding still occurs on completion of download)
Back to top
View user's profile Send private message
pdw_hu
Apprentice
Apprentice


Joined: 02 Jun 2008
Posts: 200
Location: Budapest, Hungary

PostPosted: Wed Jun 04, 2008 7:08 pm    Post subject: Reply with quote

How about including encryption and DHT in your guide, they won't hurt even if it's not being used.
Code:
dht = auto
dht_port = 666 the port of the beast ;)
encryption = allow_incoming,try_outgoing,enable_retry
Back to top
View user's profile Send private message
danomac
l33t
l33t


Joined: 06 Nov 2004
Posts: 881
Location: Vancouver, BC

PostPosted: Fri Jun 06, 2008 5:11 pm    Post subject: Reply with quote

lazx888 wrote:
So you download the torrent to an active directory, and when finished, remove the torrent and move the files to a completed directory - no seeding?

Or does schedule = ratio,60,60,"stop_on_ratio=100" determine when the torrent is "finished"??

Great work (if seeding still occurs on completion of download)


The stop_on_ratio command tells rtorrent to stop seeding torrents. The above means to stop seeding at 100%, i.e. upload the same as you've downloaded.
Back to top
View user's profile Send private message
kuku
Tux's lil' helper
Tux's lil' helper


Joined: 23 Dec 2004
Posts: 142

PostPosted: Sat Jun 07, 2008 6:40 am    Post subject: Reply with quote

danomac wrote:
lazx888 wrote:
So you download the torrent to an active directory, and when finished, remove the torrent and move the files to a completed directory - no seeding?

Or does schedule = ratio,60,60,"stop_on_ratio=100" determine when the torrent is "finished"??

Great work (if seeding still occurs on completion of download)


The stop_on_ratio command tells rtorrent to stop seeding torrents. The above means to stop seeding at 100%, i.e. upload the same as you've downloaded.

yes - on complete download there is no seeding - any idea how to change it ?
I want to delete the *.torrent file when let's say ratio is 2.0 and when it does not occur then after 1 week
Back to top
View user's profile Send private message
timbo
Apprentice
Apprentice


Joined: 29 Jul 2002
Posts: 231
Location: New Zealand

PostPosted: Wed Jun 11, 2008 8:56 pm    Post subject: Reply with quote

Hey great work with the how-to...

This app is just what I wanted bar one aspect, I want it to not download or upload anything in the evening, our ISP has free downloads (doesn't get added to your cap) durring the wee hours and thats when I want to do the downloading, can this be done with rtorrent, I can't see how.

I like being able to dump a .torrent file into a directory and it's magically downloaded, is there another app that can do this?

Regards
Tim
8)
_________________
Linux User: 303160
Back to top
View user's profile Send private message
vputz
Guru
Guru


Joined: 16 Mar 2005
Posts: 310
Location: Oxford, England

PostPosted: Wed Jun 18, 2008 10:26 am    Post subject: Reply with quote

Well, you can get close to that, from the faq:

Quote:
Scheduling download rate ¶

Quote:
schedule = throttle_1,01:00:00,24:00:00,download_rate=0
schedule = throttle_2,05:00:00,24:00:00,download_rate=25


Every day "throttle_1" gets triggered at 01:00 and sets the download rate to unlimited, while "throttle_2" sets it to 25kb at 05:00. Using this the client may be made to perform a somewhat crude form of bandwidth scheduling.
Back to top
View user's profile Send private message
DocterD
Tux's lil' helper
Tux's lil' helper


Joined: 15 May 2004
Posts: 129

PostPosted: Wed Jun 25, 2008 3:12 pm    Post subject: Reply with quote

Just for my own curiosity. Why do you not use BTG instead of rTorrent?
Back to top
View user's profile Send private message
Oak
Apprentice
Apprentice


Joined: 25 Jan 2005
Posts: 239
Location: Sweden

PostPosted: Wed Jul 09, 2008 12:43 am    Post subject: Reply with quote

DocterD wrote:
Just for my own curiosity. Why do you not use BTG instead of rTorrent?


The reason I stopped using BTG and reverted back to rTorrent, was that there weren't any way to specify which files to download from a torrent.
Some of the torrents that I download contains files that I don't want, which makes BTG unusable.

The minute that this feature is added, I'll switch back to BTG...
_________________
GCC-4.3.3-r1 - march=core2, gentoo-sources-2.6.30-r2 SMP x86_64 @ Core2Duo 2.4GHz, 4GB RAM
Back to top
View user's profile Send private message
DocterD
Tux's lil' helper
Tux's lil' helper


Joined: 15 May 2004
Posts: 129

PostPosted: Thu Jul 10, 2008 2:44 pm    Post subject: Reply with quote

Do you mean over the Webinterface? It has been added to the 0.9.8 Release.
Back to top
View user's profile Send private message
Oak
Apprentice
Apprentice


Joined: 25 Jan 2005
Posts: 239
Location: Sweden

PostPosted: Thu Jul 10, 2008 3:03 pm    Post subject: Reply with quote

Alright! Time to unmerge rtorrent...
Is version 0.9.8 available in some of the overlays?

[EDIT]
I created my own from the 0.9.7 ebuild, which complains about libboost_iostream. Version 0.9.7 complains about memset and memcpy from the stdlib...
A working 0.9.8 ebuild would be really really nice!
The 0.9.8 problem occurs in the linking process and seems to be a known problem. It says "recompile with -fPIC", which probably is meant for boost, but I can't figure out which use flag that enables this, if any.
[/EDIT]
_________________
GCC-4.3.3-r1 - march=core2, gentoo-sources-2.6.30-r2 SMP x86_64 @ Core2Duo 2.4GHz, 4GB RAM
Back to top
View user's profile Send private message
DocterD
Tux's lil' helper
Tux's lil' helper


Joined: 15 May 2004
Posts: 129

PostPosted: Sun Jul 13, 2008 11:47 am    Post subject: Reply with quote

Yeah i got the same Problem with compiling rb_libtorrent-0.13.1
Back to top
View user's profile Send private message
Oak
Apprentice
Apprentice


Joined: 25 Jan 2005
Posts: 239
Location: Sweden

PostPosted: Mon Jul 14, 2008 5:39 pm    Post subject: Reply with quote

DocterD wrote:
Yeah i got the same Problem with compiling rb_libtorrent-0.13.1


What about version 0.13? For me it compiles just fine, but unfortunately, btg still doesn't

[EDIT]

I finally got btg-0.9.7 to compile after modifying a couple of source files and disabling the gtk2 use flag. Since I've never created a patch before, I simply created an archive with the new files and a small shell script to insert them. If someone finds it useful, you're very welcome to create a patch from it. I'm using rb_libtorrent-v0.13 and gcc-4.3.1 by the way

http://www.oakstream.org/files/btg-0.9.7-header_fix.tar.gz

[/EDIT]
_________________
GCC-4.3.3-r1 - march=core2, gentoo-sources-2.6.30-r2 SMP x86_64 @ Core2Duo 2.4GHz, 4GB RAM
Back to top
View user's profile Send private message
Mounir Lamouri
Retired Dev
Retired Dev


Joined: 23 Jul 2006
Posts: 13
Location: Montreal, QC

PostPosted: Wed Jul 16, 2008 1:28 pm    Post subject: Reply with quote

I've written a btg-0.9.8 ebuild (see bug link at the end of the message) and Dennis told me there was a compilation error.

After reading this doc : http://www.gentoo.org/proj/en/base/amd64/howtos/index.xml?part=1&chap=3
and as I see you and Dennis have a 64 bits system, I think it's a 64 bits related issue with -fPIC.

Actually, it looks more like a boost issue than a btg one but I don't see any other similar bug...
So, I suppose it can be managed only on btg but I really don't know how. Does someone have an experience here ?

Note : may be this topic should be cut by a moderator...?
or should this discussion continued here : https://bugs.gentoo.org/show_bug.cgi?id=231105
Back to top
View user's profile Send private message
Oak
Apprentice
Apprentice


Joined: 25 Jan 2005
Posts: 239
Location: Sweden

PostPosted: Wed Jul 16, 2008 1:38 pm    Post subject: Reply with quote

Actually, the "-fPIC problem" isn't really a problem anymore, at least for me. As stated in my last post, the only problem left is the missing headers in btg which are easy to fix.
I'll try the 0.9.8 version later today and report back here as soon as possible.
_________________
GCC-4.3.3-r1 - march=core2, gentoo-sources-2.6.30-r2 SMP x86_64 @ Core2Duo 2.4GHz, 4GB RAM
Back to top
View user's profile Send private message
Mounir Lamouri
Retired Dev
Retired Dev


Joined: 23 Jul 2006
Posts: 13
Location: Montreal, QC

PostPosted: Wed Jul 16, 2008 1:44 pm    Post subject: Reply with quote

Dennis Oberhoff told me 0.9.7 was compiling correctly on is system so I supposed -fPIC error appeared with 0.9.8. May be with boost 1.35 ?
Did you had fPIC error with 0.9.7 ebuild ?
Back to top
View user's profile Send private message
Display posts from previous:   
Reply to topic    Gentoo Forums Forum Index Documentation, Tips & Tricks All times are GMT
Goto page 1, 2  Next
Page 1 of 2

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum