Jump to content

rtorrent


boof

Recommended Posts

s there any way to externally signal rtorrent to shutdown cleanly (equivalent to pressing ctrl-q on the qui)? If there is, then it would perhaps make it more beneficial to explore this deamonising little further. There are other torrent clients with cli but as this is already nicely packaged for unRAID there is no point looking for others.

 

Sent an INT to the pid of rtorrent.

 

kill -INT ${PID} 2>/dev/null

 

Where $PID is the value of rtorrent's pid.

 

 

I have an elaborate rc.rTorrent script to start and stop rtorrent in the background using screen.

 

Then I have a screens command which lists all background screens in a menu so it's easier to connect.

It's not a perfect script and it's a bit large, but I'll post it if people want a starting point.

Link to comment
  • Replies 91
  • Created
  • Last Reply

Edit: Weebotech beat me to it by few minutes ;) I would at least be interested with a full rc.rtorrent and screen scripts! I think in general it would be very nice to have a dedicated thread where people could just post their startup/shutdown/utlitity scripts.

--------------------------------------------------------------------------------------------------

Perhaps I should have spent some time on research before asking here  :-[

 

With some basic googling I found that rtorrent in particular is a quite common application to be shutdown externally. The most common way I found was to use the SIGINT signal with kill enhanced with >5 second delay afterwards (rtorrent is said to shutdown in less than 5 seconds):

#!/bin/bash

# rtorrent
if [[ -n `pidof rtorrent` ]];then
echo "rtorrent is open, time to die (gracefully)...."
kill -2 `pidof rtorrent`
        sleep 10
fi

This could be quite easily further enhanced by checking periodically when rtorrent is really shutdown thus making the constant delay obsolete. At the same time you could add forcefull shutdown in case gracefull was unsuccessfull and make clean up by removing the potential lock file.

 

All this is quite nice but does not really solve the problem of reacting array stop situation. I think I will start solving that by using cache disk (or other non-array disk) as the work disk for rtorrent. Or if I really want educate myself I could perhaps borrow the array stop sensing mechanism from cache_dirs (ala Joe L.):

# if the user attempted to stop the array, terminate this process so it can be stopped next time they try.
    stop_attempt=`tail -200 /var/log/syslog | egrep "devices still in use|mdcmd.*stop|Retry unmounting disk share"`
    if [ "$stop_attempt" != "" ] 
    .......................    
    

 

This could be added to some generic background script running periodically whose only purpose would be to signal array stop properly to all necessary applications.

 

Link to comment

This could be added to some generic background script running periodically whose only purpose would be to signal array stop properly to all necessary applications.

 

...thus making a generic framework to handle a bunch of add-ons if need be? This sounds pretty good.

 

 

Link to comment

This could be added to some generic background script running periodically whose only purpose would be to signal array stop properly to all necessary applications.

 

...thus making a generic framework to handle a bunch of add-ons if need be? This sounds pretty good.

 

Before we start on this possibility, Tom made a post that there may be be an early 5.0 beta for Christmas programming fun. heh.  Let's see what limetechclaus brings  ;D

Link to comment

This could be added to some generic background script running periodically whose only purpose would be to signal array stop properly to all necessary applications.

 

...thus making a generic framework to handle a bunch of add-ons if need be? This sounds pretty good.

 

 

We could actually do this now, as unRAID will now refuse to shut down unless all the disks can be un-mounted (and are not busy)

I've been waiting for Tom to get a bit further before starting, but my ideas are to use a system very similar to the rc.X scheme, but with our own files located in /boot/custom/etc  (at least for now)

 

The script used to start add-ons would use something like

/boot/custom/etc/rc.d/rc.rtorrent start

To stop one, it would use something like

/boot/custom/etc/rc.d/rc.rtorrent stop

 

This would require a rewrite of almost all of the scripts I have in my custom rc.d folder to handle properly the "start" and "stop" arguments.

 

The only other issue would be how to communicate success/failures back to the main web-interface Tom is in the process of writing.  And of course, this assumes he does not have an alternate better idea of how/where to put start-up/shut-down scripts.

 

As you said, cache_dirs has both the method to detect the array being on-line (new presence of /mnt/user, where it was not present before the array starts) and the method to detect the desire to stop (messages in the syslog) and a method to keep a disk busy on it own to ensure we get the messages in the syslog to act on them (child process with current working directory as one of the data disks)

 

This should all be continued in a thread of its own...  A dedicated shell script looping for these events can trigger and process start up scripts and stop scripts in rc.d.  When Tom gets further along, the monitoring loop can be replaced by triggers he initiates.

 

I'm waiting to see what Santa Brings...  ;D ;D

 

Joe L.

Link to comment
This should all be continued in a thread of its own...  A dedicated shell script looping for these events can trigger and process start up scripts and stop scripts in rc.d.  When Tom gets further along, the monitoring loop can be replaced by triggers he initiates.

 

I agree, this is a good idea, start a thread, but I would suggest waiting a few weeks to see what's in the pipeline.

I started this sort of process with the rc.unRAID script in the power down package.

I could move further along with this. Learned a thing or too about file locking at the shell level which would actually elimate the sleep loop on all the children in cache_dirs... I've just held off until I see what santatech brings. ;-)

 

Start a new thread for discussion.

Link to comment

So here are some rtorrent and dependencies packages I've made myself.

[...]

- compiled with xmlrpc-c support ready for web interfaces

[...]

   389587  07-14-09 16:29   rtorrent-0.8.4-i486-1.tgz

 

Boof,

 

Could you possibly make a package of rtorrent-0.8.5?

 

I have no idea how much trouble that would be.  :)

 

Purko

 

 

Link to comment

So here are some rtorrent and dependencies packages I've made myself.

[...]

- compiled with xmlrpc-c support ready for web interfaces

[...]

   389587  07-14-09 16:29   rtorrent-0.8.4-i486-1.tgz

 

Boof,

 

Could you possibly make a package of rtorrent-0.8.5?

 

I have no idea how much trouble that would be.  :)

 

Purko

 

 

 

Not too much trouble although you'd have to wait till tomorrow!

 

Is there something bad about 0.8.6 we've missed?

Link to comment

ah phew - I take it you're all good with 0.8.6 from the first post?

 

I have not even realised that there's 0.8.6 there!   :o

 

I made my post as a reply to that first post there, and it's still showing 0.8.4.

Sorry for the confusion!

 

 

 

Should be - I made a post bumping this thread to let everyone know but I think it's now several pages old after the recent lively discussion :)

 

It only went up yesterday courtesy of flixxx.

Link to comment

Update 2009-12-12:

- v0.2 of the rc.rtorrent script, changes:

  * Added the configuration of session directory location

  * Removed the configuration of lock file location

  * Added a check for existence of configuration file and session directory.

  * Added a check that rtorrent is really started

  * rc.rtorrent status now prints the configuration

- Included an example rtorrent.rc configuration file which is coupled with rc.rtorrent configuration

 

-----------------------------------------------------------------------------------------------------------------------------------------

 

Well here (attached and below) is rc.rtorrent with start/stop/restart/activate/status functions mimicing the behaviour of a daemon. I tried to make the script robust from the beginning introducing a lot of "non-functional" lines but hey better safe than sorry ;). I took it mostly as a crash course to bash scripting. Most of the code is actually quite generic so this could be used also as "base class" for most applications. I just don't know yet how you would nicely "derive" the application specific parts (plugins or hooks etc.) using bash. I would really hate to copy-paste 95% of the code to use it on another application. Feel free to use this as you like.

 

Now I'm just waiting for Joe L. / Weebotech / Boof and others to kick start the "unRAID status polling framework" development. Currently this script is totally unaware of array stops so if you use array disks for rtorrent storage remember to stop this service before stopping the array or shutting down the server. It could be that normal shutdown procedure brings things down in proper order (this first and then the array) but I really can't guarantee that.

 

I've tried to test this to best of my ability to test this and since this doesn't do anything destructive it should be safe to use. Do it still on your own risk ;)

 

Installation

1. have the rtorrent and screen packages (with dependencies) installed

   - Flixx's guide (http://lime-technology.com/forum/index.php?topic=4827.0) can be used as basis. unRAIDWeb and RUTorrent parts are not mandatory.

 

2. Save rc.rtorrent script for example to "/boot/custom/etc/rc.d/".

 

3. Modify (eg. with mcedit) the few mandatory configurable parameters located at the top of rc.rtorrent script

    - session_dir: This should point to the session directory (set in the config file) eg. "/mnt/disk1/rtorrent/session

    - config_file: This should point to your rtorrent configuration file eg. "/mnt/disk1/rtorrent/config/rtorrent.rc"

 

4. Optional: Add the directory where you stored the script to the system path. Otherwise you will have to use full path to rc.rtorrent when using it.

 

5. Optional: Configure rtorrent to start on unRAID startup by adding the following line into your go script

/boot/custom/etc/rc.d/rc.rtorrent start

 

Usage

1. Start rtorrent

rc.rtorrent start

2. Stop rtorrent (gracefully if possible)

rc.rtorrent stop

3. Restart rtorrent

rc.rtorrent restart

4. Query the status of rtorrent "daemon", prints out also the the current configuration

rc.rtorrent status

5. Activate rtorrent gui (attach to the correct screen)

rc.rtorrent activate

screen -r rtorrentd

 

rc.rtorrent (the main script)

#!/bin/bash

# ******************************************************************************
# rc.rtorrent 
# "daemon emulation" script for rtorrent/screen  to be used with UnRAID
#
# Version 0.2 2009-12-12 Added the configuration of session directory location
#			 Removed the configuration of lock file location
#			 Added a check for existence of configuration file and
#			 session directory.
#			 Added a check that rtorrent is really started
#			 rc.rtorrent status now prints the configuration
# Version 0.1 2009-12-11 First release
#
# ******************************************************************************

# --------- Modify the following according to your setup 
# rtorrent's sessions directory
# Session directory is onfigured in rtorrent.rc (insert here without trailing slash)
session_dir=/mnt/disk6/torrent/session
# rtorrent config file
config_file=/mnt/disk6/torrent/config/rtorrent.rc
# --------- Do not modify anything below this

# rtorrent gracefull shutdown maximum wait time in seconds (more than 10 secs recommended)
max_shutdown_waittime=30
# lock file (automatically derived from session directory, do not modify
lock_file=$session_dir"/rtorrent.lock"

rtorrent_start()
{
    # start only if not already running
    if [[ -n `pidof rtorrent` ]];then
echo "rtorrent is already running. Use rc.rtorrent activate to attach and Ctrl-a-d to detach."
    else
# check that the config file exists
if [ ! -f $config_file ];then
    echo "Defined rtorrent configutation file '"$config_file"' does not exist. Please modify rc.rtorrent."
    exit
fi	
# check that the session directory exists
if [ ! -d $session_dir ];then
    echo "Defined session directory '" $session_dir "' does not exist. Please modify rc.rtorrent."
    exit
fi

echo "Starting rtorrent..."
# Removing lock file in case of ungracefull shutdown
if [ -f "$lock_file" ]; then
    echo "Lock file found from previous session, removing..."
    rm -f $lock_file 
fi
# Disable ctrl-s and ctrl-q key mappings which are used by rtorrent
stty start undef
stty stop undef
# Run rtorrent in screen (use screen -r to attach and ctrl-a-d to detach)
/usr/bin/screen -dmS rtorrentd /usr/bin/rtorrent -n -o import=$config_file
# Create symbolic link for .screen if it does not exist
if [ ! -e "/root/.screen" ]; then
    ln -s /.screen /root/
fi
# check that rtorrent really started
if [[ -n `pidof rtorrent` ]];then
    echo "rtorrent started."
    echo "Use 'rc.rtorrent activate' or 'screen -r rtorrentd' to activate rtorrent gui."
    echo "Use Ctrl-a-d to deactivate rtorrent gui and leave it running in the background."
else
    echo "Unable to start rtorrent. Unknown error."
fi
    fi
}

rtorrent_stop()
{
    # stop only if running
    if [[ -n `pidof rtorrent` ]];then
echo -n "rtorrent is running, shutting down gracefully with SIGINT["
kill -SIGINT `pidof rtorrent`
# waiting for rtorrent to shutdown (maximum of max_shutdown_waittime seconds)
shutdown_counter=0
while [  $shutdown_counter -lt $max_shutdown_waittime ]; do
    # if process is not yet shutdown, sleep 1 second
    if [[ -n `pidof rtorrent` ]];then
	echo -n "."
	sleep 1
	let shutdown_counter=shutdown_counter+1
    # if process finished exit while
    else
	let shutdown_counter=$max_shutdown_waittime
    fi
done
echo "]"
# if rtorrent is still running SIGINT did not work -> kill forcefully
if [[ -n `pidof rtorrent` ]];then
    echo "rtorrent not responding to SIGINT, forcing shutdown with SIGKILL..."
    kill -SIGKILL `pidof rtorrent`
fi
# if rtorrent is still running kill SIGKILL -> nothing can be done
if [[ -n `pidof rtorrent` ]];then
    echo "Unable to shut down rtorrent. Giving up..."
else
    echo "rtorrent shut down successfully"
fi
    else
echo "rtorrent not running, nothing to do"
    fi
}

rtorrent_restart()
{
    # stop only if already running
    if [[ -n `pidof rtorrent` ]];then
rtorrent_stop
    fi
    rtorrent_start
}                           

rtorrent_activate()
{
    if [[ -n `pidof rtorrent` ]];then
screen -r rtorrentd
    else
echo "rtorrent is not running"
    fi
}

rtorrent_printconfiguration()
{
    echo "rc.rtorrent configuration:"
    echo "- session directory: '"$session_dir"'"
    echo "- rtorrent.rc configuration file: '"$config_file"'"
}


rtorrent_status()
{
    if [[ -n `pidof rtorrent` ]];then
echo "rtorrent is running."
    else
echo "rtorrent is not running"
    fi
    echo 
    rtorrent_printconfiguration
}

case "$1" in
    'start'  ) rtorrent_start   ;;
    'stop'   ) rtorrent_stop    ;;
    'restart') rtorrent_restart ;;
    'activate') rtorrent_activate ;;
    'status' ) shift; rtorrent_status $@;;
    *) echo "usage $0 start|stop|restart|activate|status";;
esac

 

rtorrent.rc (example rtorrent configuration)

# This is an example resource file for rTorrent. Enable/modify the options as 
# needed. Remember to uncomment the options you wish to enable.
#
# Note! The default example has been modified mostly to suit unattended torrent
# loading. It includes agressive automatic stop and remove of torrents
# with correct ration control configuration for rtorrent v0.84 and up.
# To use it you need to modify atleast the used download, session,
# watch and finished directories.
#
# The configuration is based on the following directory structure:
# download = /mnt/disk6/torrent/download
# session = /mnt/disk6/torrent/session
# watch = /mnt/disk6/torrent/watch
# finished = /mnt/disk6/torrent/finished
#
# Resources:
# http://libtorrent.rakshasa.no/wiki/RTorrentUserGuide
# http://libtorrent.rakshasa.no/browser/trunk/rtorrent/doc/rtorrent.rc#latest
# http://libtorrent.rakshasa.no/wiki/RTorrentCommonTasks

# Maximum and minimum number of peers to connect to per torrent.
#min_peers = 40
max_peers = 52

# Same as above but for seeding completed torrents (-1 = same as downloading)
#min_peers_seed = 10
max_peers_seed = 52

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

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

# Default directory to save the downloaded torrents.
directory = /mnt/disk6/torrent/download

# Default session directory. Make sure you don't run multiple instance
# of rtorrent using the same session directory.
session = /mnt/disk6/torrent/session

# Watch a directory for new torrents, and stop those that have been
# deleted.
schedule = watch_directory,5,5,load_start=/mnt/disk6/torrent/watch/*.torrent
schedule = untied_directory,5,5,stop_untied=

# Close torrents when diskspace is low (10GB in this case)
schedule = low_diskspace,5,60,close_low_diskspace=10000M

# Enable the default ratio group.
ratio.enable=
# Change the limits (defaul/recommended values are 100, 300, 20M)
ratio.min.set=20
ratio.max.set=30
ratio.upload.set=20M

# Changing the command triggered when the ratio is reached.
# This will cause the torrent to be stopped and removed from the list
system.method.set = group.seeding.ratio.command, d.close=, d.erase=

# When download is finished move torrent to a different directory
system.method.set_key = event.download.finished,move_complete,"execute=mv,-u,$d.get_base_path=,/mnt/disk6/torrent/finished/;d.set_directory=/mnt/disk6/torrent/finished/"

# The ip address reported to the tracker.
#ip = 127.0.0.1
#ip = rakshasa.no

# The ip address the listening socket and outgoing connections is
# bound to.
#bind = 127.0.0.1
#bind = rakshasa.no

# Port range to use for listening.
port_range = 49164-49164

# Start opening ports at a random position within the port range.
#port_random = no

# Check hash for finished torrents. Might be usefull until the bug is
# fixed that causes lack of diskspace not to be properly reported.
check_hash = no

# Set whetever the client should try to connect to UDP trackers.
#use_udp_trackers = yes

# Alternative calls to bind and ip that should handle dynamic ip's.
#schedule = ip_tick,0,1800,ip=rakshasa
#schedule = bind_tick,0,1800,bind=rakshasa

# Encryption options, set to none (default) or any combination of the following:
# allow_incoming, try_outgoing, require, require_RC4, enable_retry, prefer_plaintext
#
# The example value allows incoming encrypted connections, starts unencrypted
# outgoing connections but retries with encryption if they fail, preferring
# plaintext to RC4 encryption after the encrypted handshake
#
# encryption = allow_incoming,try_outgoing,enable_retry

# Enable DHT support for trackerless torrents or when all trackers are down.
# May be set to "disable" (completely disable DHT), "off" (do not start DHT),
# "auto" (start and stop DHT as needed), or "on" (start DHT immediately).
# The default is "off". For DHT to work, a session directory must be defined.
# 
dht = auto

# UDP port to use for DHT. 
# 
dht_port = 6881

# Enable peer exchange (for torrents not marked private)
#
peer_exchange = yes

#
# Do not modify the following parameters unless you know what you're doing.
#

# Hash read-ahead controls how many MB to request the kernel to read
# ahead. If the value is too low the disk may not be fully utilized,
# while if too high the kernel might not be able to keep the read
# pages in memory thus end up trashing.
#hash_read_ahead = 10

# Interval between attempts to check the hash, in milliseconds.
#hash_interval = 100

# Number of attempts to check the hash while using the mincore status,
# before forcing. Overworked systems might need lower values to get a
# decent hash checking rate.
#hash_max_tries = 10

Link to comment
  • 1 year later...

Sorry to revive such an old thread, but anybody got rtorrent 0.8.9 compiled for unraid 4.6?

 

I've always experienced random crashes with rtorrent under unraid with many torrents (usually when I have more than 40); sometimes rtorrent will run without crashing for 2 weeks, sometimes 2 days.

 

I have a feeling 0.8.9 might fix some of the issues I've been experiencing.

Link to comment
  • 3 weeks later...

Archived

This topic is now archived and is closed to further replies.


×
×
  • Create New...