0

I run a seed-box like local machine with Ubuntu 14.04LTS setup with multi-user rtorrent/rutorrent.

I installed that through a script that also installed crontab entries for each user so rtorrent & irrsi would start automatically at boot.

Load is too high (especially on the network) if all users rtorrent/irrsi are running at the same time. So I have started to

su - user
password
crontab -e

& then comment these rtorrent/irrsi lines out for users A-D & uncomment them for users E-H.

Later at night, when I return from work, I do the same but uncomment these lines for users A-D & comment these lines out for users E-H.

All this editing has made me starting to wonder if there wouldn't be an easier way to accomplish this... Would there be a way of creating a script that adds a # in front of all the lines in the crontab of all the users I specify. And then maybe a second script to remove that # (if present).

EDIT: each users' crontab contains only these 2 lines.

@reboot sleep 10; /usr/local/bin/rtcheck irssi rtorrent
*/5 * * * * /usr/local/bin/rtcheck irssi rtorrent

When I don't want them to be run at reboot or later, when cron finds them not running, I just comment out these lines so they look like this:

#@reboot sleep 10; /usr/local/bin/rtcheck irssi rtorrent
#*/5 * * * * /usr/local/bin/rtcheck irssi rtorrent

making it effectively neither irssi nor rtorrent start a boot nor get started later when cron finds them not running.

  • Welcome to AU ! Can you show us a couple of those crontab entries ? (Please add them a the end of yr original post.) – Cbhihe Jul 25 '16 at 6:27
  • Should we assume this is a regular user's crontab and not root's ? – Cbhihe Jul 25 '16 at 10:05
  • dont! use /etc/crontab No need to mess with every users crontab when you can use that one and include a username. 1 place to store them. 1 place to edit them. And you reaaaaaaaaally should check the user name in a script and not edit crontabs. – Rinzwind Jul 25 '16 at 18:01
  • No, I don't want to do this for the root crontab, only for all other users related to rtorrent. I just added the entries that are in each users crontab (except root). – zotteken Jul 25 '16 at 21:09
0

Probably the simplest way of doing this with cron is to:

  • start the torrent service at time T1 for each user in user group A
  • stop the torrent service at time T2>T1 for users in group A
  • start the torrent service at time T2>T1 for users in group B
  • stop the torrent service at time T3>T2 for users in group B

Choose times, e.g.

  • T1 is anywhere between 0:01 am and 1:59 pm on D-day
  • T2 is 2:00 pm on D-day
  • T3 is 11:59 pm on D-day

You can change that anyway you like to make time sharing equitable for all group A and B users.

For user "username" in group A:
1) Edit existing crontab entries by commenting them out. Don't erase them just comment them out so they do not fire.
2) Add new crontab entries:

# => either start daemon, while checking that (i) startup takes place between 0:01 am
#+ and 2:00pm and (i) no 'rtorrent' process owned by "username" already runs. 
*/10 0-14 * * * [ -z $(/bin/ps -eF | /usr/bin/awk '/rtorrent/ && /username/') ] && /sbin/start-stop-daemon -S /usr/local/bin/rtorrent  
# => or start client-app based on similar conditions
*/10 0-14 * * * [ -z $(/bin/ps -eF | /usr/bin/awk '/rtorrent/ && /username/') ] && /usr/bin/env DISPLAY=:0.0 /usr/local/bin/rtorrent  

# stop 'rtorrent' process if it exists and is owned by "username"
#+ Check every 5 minutes between 2pm and midnight
*/5 14-24 * * * /usr/bin/kill "$(/bin/ps -eF | /usr/bin/awk '/rtorrent/ && /username/ printf "%s",$2')"  > /dev/null 2>&1

Details of the command starting yr daemon will depend on a number of factors, e.g. whether the client starting rtorrent is a single user machine or whether several user can simultaneously run their own instance of rtorrent. In this case you may want to save the process pid in a run-file for each user so you can manage those processes as a unction of traffic load. Look at this to actually start the rtorrent process identifying user, socket and pid.

I could not tried this solution, so it is a bit of a foray in the dark as far as the correct start procedure is concerned. In particular I assume that yr /home/username/.rtorrent.rc is adequately configured, and that irssi gives you no trouble as detailed elsewhere.

HTH. Please report.

  • I wasn't really looking to schedule it at fixed times. I'd rather run a command at a moment of my convenience that'll kill the running instances I don't want to be running & fires up the instances I do want. However, since seeing your solution, I have started to like the idea more & more. I will give it a try. – zotteken Jul 27 '16 at 6:38
  • If you mention the cron flag and you show a crontab entry in PO, then it's logical to surmise that you want to run the jobs automatically and not manually. Note that the crontab enty I included are solutions that fire up the service at any time between midnight and 2pm after boot for group A users, and to shut down the same rtorrent client any time between 2pm and midnight. I propose that, so that any group A user that fires up his/her torrentclient after 2pm will see it being automatically closed after 5 minutes tops. Doing so you actually regulate rtorrent` usage by group. HTH – Cbhihe Jul 28 '16 at 7:40
  • You can do the same for group B users and their rtorrentsessions. You can actually partition yr 24 hrs in any number of times windows to accommodate any number of user groups, so that you concede to them the possibility to run rtorrent during a time period you specify in advance. – Cbhihe Jul 28 '16 at 7:43
  • OK, I admit my way of putting the question was a bit misleading. I already told I gonna try your solution. I have not yet been able to implement it though. I plan on doing 3 groups which each get 8 hours of the day. – zotteken Aug 2 '16 at 18:07

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.