You are not logged in.
Good day to all Archers,
First off, what I'd like to accomplish (in case what I'm currently trying is not the best way):
I have an HP Proliant server connected to my home network. This server runs programs such as ps3mediaserver, rssdler and rtorrent (all in screen sessions to easily manage with ssh). I live in the Republic of South Africa, and as such my internet situation is not too great. My ISP markets my account as an uncapped 1mbps account (1mbps is near top-of-the-line here) but it is shaped using a 2 tier rolling window scheme. Basically, between the hours of 06:00:00 and 24:00:00 my total usage (down and up) for the past 6 hours must not exceed 800MB. This means that I cannot download anything between those hours and should only browse.
I've tried scheduling in rtorrent's .rtorrentrc (as the ideal solution) but I'm only allowed to change the rate to 1kB/s. In fact I see a much higher rate than that when it's set but even if it were as low it's still too much for me. I've read about using d.multicall and d.stop and so on but this doesn't work for me since I want to selectively pause all active (possible) and then start those same ones again (and not the ones that were inactive all along). I couldn't figure out how to do this and those commands don't work as the tin says for me anyway.
I then tried another route (as the internet suggested) and that is to use cron to start and stop rtorrent completely. If rtorrent starts again, all will be as it was plus the torrents added in the watch directory. From there I ran into numerous problems:
1) Starting rtorrent with
screen -d -m -S rtorrent rtorrentsuccessfully creates a detached screen session named rtorrent with rtorrent running inside. If I then attach the session and try quitting rtorrent with C-q, nothing happens. On the other hand, if I first created the screen session (attached) and then started rtorrent inside C-q works. This is the case regardless of the -f, -fa or -fn options. I (think) I cannot attach into a screen session using cron though. Starting rtorrent after screen using:
screen -S rtorrent -X exec /usr/bin/rtorrentdoes not solve the issue. I then thought about simulating what works like:
screen -S rtorrent -X stuff "rtorrent"
screen -S rtorrent -X eval 'stuff \015'however some bug causes the -X commands sometimes not to be executed meaning I'd have to do it several time and I don't want cron to do that.
2) Ignoring issue 1 thinking that its no big deal to kill rtorrent externally, I moved on. Now trying to kill externally is not so simple. Regardless of how I do it:
pkill -2 rtorrentor
screen -S rtorrent -X eval 'stuff \021'or using kill with the PID, when rtorrent is killed, screen also terminates. I'd like to send SIGINT to rtorrent, wait for it to die, and then terminate the screen so that rtorrent has a chance to close threads and die gracefully. I don't know why screen also terminates and whether it waits for its child processes to die before it dies. If it waits, that's fine. Otherwise I need a way to kill rtorrent (which is running as child of screen session) without killing screen. Then I can live with issue 1.
I'd appreciate any advice or any other method of accomplishing what I want.
Thanks in anticipation,
A.L.
Last edited by ArseneLupin (2012-02-06 21:12:30)
Offline
Offline
Thank you for your advice.
I saw that article on the wiki and was under the impression that using options "-fn" etc. has the same effect. Guess not, since doing what you mentioned made the difference.
Regarding running as daemon:
I saw that article also and foolishly thought "that's only for people who want to run at startup". I will look at the script and maybe use it as-is.
[EDIT]
Just looked at the daemon script and it seems to do exactly what I'm doing (using killall instead of pkill though). Assuming this will have the same effect as what I described in point 2 above, please only answer my last question in this post - if anyone knows - before I mark this as solved.
[/EDIT]
Still, seeing as issue 1 is now resolved, I'd still like to know:
After adding "defflow off" to .screenrc, quitting rtorrent manually with C-q still terminates screen when it was started at the time the session was created, ie
screen -d -m -S screenname rtorrentbut not when starting rtorrent after creating the screen session, inside the session ie:
screen -S screennamefollowed by
rtorrent.
I'm beginning to suspect that that is just screen's behaviour...if it was started along with a process it will terminate as soon as that process stops existing. If that's the case and rtorrent quits safely and not abruptly because of screen terminating then I'm a happy man.
Anyway, thanks for the reply. I'm fully aware that my post might look long and complicated but screen sessions tend to complicate things.
Your friend,
A.L.
Last edited by ArseneLupin (2012-02-06 19:26:06)
Offline
After searching again and again I noticed a part in the Overview section of GNU screen manual , I quote:
When a program terminates, screen (per default) kills the window that contained it. If this window was in the foreground, the display switches to the previously displayed window; if none are left, screen exits.
In other words, when starting a session with a process only 1 window existed containing that process - it dies, session dies. When starting an empty session and then starting a process in it, 2 windows exist. One containing the shell and the other the new process, kill the process and that window is killed leaving the still-in-tact shell window open.
I tested this to make sure by running a script with an infinite loop when starting a new session that echos a countdown when getting SIGINT (via trap). The countdown finishes beautifully and THEN screen terminates.
I can now schedule cron my way.
Thanks KingX for leading me to the answer..SOLVED!
A.L.
Offline
You're welcome. ![]()
Last edited by KingX (2012-02-06 21:41:08)
Offline