Bug#373152: cron should randomize /etc/crontab to be more friendly to virtual servers

2012-05-11 Thread LordBaco

Another alternative in bash :

#!/bin/bash
# randomize /etc/crontab
test -f /var/backups/crontab-orig || cp /etc/crontab /var/backups/crontab-orig
SUM=`sum -s /etc/hostname | cut -d" " -f1`
H=$[ 6 - ( $RANDOM % 2 ) ]
M=`printf "%02d" $[ ( $SUM ) % 60 ] `
sed -i -e "s/^[0-9]*\(.*cron\.hourly.*\)/$M\1/" "/etc/crontab"
sed -i -e "s/^[0-9]* [0-9]*\(.*cron\.daily.*\)/$M $H\1/" "/etc/crontab"
H=$[ $H - 1 ]
sed -i -e "s/^[0-9]* [0-9]*\(.*cron\.weekly.*\)/$M $H\1/" "/etc/crontab"
H=$[ $H - 1 ]
sed -i -e "s/^[0-9]* [0-9]*\(.*cron\.monthly.*\)/$M $H\1/" "/etc/crontab"

Best Regards,
Guy Baconniere


--
To UNSUBSCRIBE, email to debian-bugs-dist-requ...@lists.debian.org
with a subject of "unsubscribe". Trouble? Contact listmas...@lists.debian.org



Bug#373152: cron should randomize /etc/crontab to be more friendly to virtual servers

2012-05-08 Thread LordBaco

# One-liner
perl -p -i -e 'if(/run-parts/) { s/^\d+/unpack("%32C*",qx{hostname -s})%60/e; 
s/^([\d*]+\s+)\d+/$1.($.-8)/e; }' /etc/crontab

The above one-liner will randomize the minute and the hour of all "run-parts" 
lines of /etc/crontab on Debian
I calculate the System V sum of the hostname modulo 60 to generate the second. 
For the hour i am using
the line number minus 8.

SYSTEM A
--- crontab 2008-09-28 11:07:29.0 +
+++ crontab 2012-05-08 17:09:31.783311749 +
@@ -8,10 +8,10 @@
 PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
 
 # m h dom mon dow user command
-17 *   * * *   rootcd / && run-parts --report /etc/cron.hourly
-25 6   * * *   roottest -x /usr/sbin/anacron || ( cd / && run-parts 
--report /etc/cron.daily )
-47 6   * * 7   roottest -x /usr/sbin/anacron || ( cd / && run-parts 
--report /etc/cron.weekly )
-52 6   1 * *   roottest -x /usr/sbin/anacron || ( cd / && run-parts 
--report /etc/cron.monthly )
+42 *   * * *   rootcd / && run-parts --report /etc/cron.hourly
+42 4   * * *   roottest -x /usr/sbin/anacron || ( cd / && run-parts 
--report /etc/cron.daily )
+42 5   * * 7   roottest -x /usr/sbin/anacron || ( cd / && run-parts 
--report /etc/cron.weekly )
+42 6   1 * *   roottest -x /usr/sbin/anacron || ( cd / && run-parts 
--report /etc/cron.monthly )
 #

SYSTEM B
--- crontab 2008-09-28 11:07:29.0 +
+++ crontab 2012-05-08 17:37:06.940635403 +
@@ -8,10 +8,10 @@
 PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
 
 # m h dom mon dow user command
-17 *   * * *   rootcd / && run-parts --report /etc/cron.hourly
-25 6   * * *   roottest -x /usr/sbin/anacron || ( cd / && run-parts 
--report /etc/cron.daily )
-47 6   * * 7   roottest -x /usr/sbin/anacron || ( cd / && run-parts 
--report /etc/cron.weekly )
-52 6   1 * *   roottest -x /usr/sbin/anacron || ( cd / && run-parts 
--report /etc/cron.monthly )
+47 *   * * *   rootcd / && run-parts --report /etc/cron.hourly
+47 4   * * *   roottest -x /usr/sbin/anacron || ( cd / && run-parts 
--report /etc/cron.daily )
+47 5   * * 7   roottest -x /usr/sbin/anacron || ( cd / && run-parts 
--report /etc/cron.weekly )
+47 6   1 * *   roottest -x /usr/sbin/anacron || ( cd / && run-parts 
--report /etc/cron.monthly )
 #

After we can also imagine using gmtime()  to get the minute/hour instead of the 
modulo 60 or
using int(rand(3)+4) to randomize the hour between 4 and 7.

Best Regards,
Guy Baconniere








--
To UNSUBSCRIBE, email to debian-bugs-dist-requ...@lists.debian.org
with a subject of "unsubscribe". Trouble? Contact listmas...@lists.debian.org



Bug#373152: cron should randomize /etc/crontab to be more friendly to virtual servers

2010-04-15 Thread Christian Kastner
severity 373152 wishlist
merge 373152 522419
thanks

In my own experience, the only proper approach -- guaranteeing "safe"
system loads -- is a managed solution, ie either custom crontabs for the
guests or having cron jobs managed by the host (as Russell plans to do).

Nevertheless, I understand the need for this. One possible solution
might be a CRON_RANDOMIZE= setting, after which all jobs are run at

specified time + random integer between 0 and  seconds


Given the number of tasks still do be done, I highly doubt that this
will be implemented anytime soon.


Christian



signature.asc
Description: OpenPGP digital signature


Bug#373152: cron should randomize /etc/crontab to be more friendly to virtual servers

2006-06-13 Thread Olivier Macchioni
Package: cron
Version: 3.0pl1-86
Severity: normal


I'm using a setting with 6 virtual Debian servers.

All their system cronjobs start at the same time, which eats all the
ressources of the server at the same time (especially updatedb every
morning at 6:25). The servers all basically come to a halt because
of HD / CPU usage.

I beleive it would be good to introduce some randomization in the start
time.



-- System Information:
Debian Release: 3.1
Architecture: i386 (i686)
Kernel: Linux 2.6.15.1
Locale: LANG=C, LC_CTYPE=C (charmap=ANSI_X3.4-1968)

Versions of packages cron depends on:
ii  adduser   3.63   Add and remove users and groups
ii  debianutils   2.8.4  Miscellaneous utilities specific t
ii  libc6 2.3.2.ds1-22sarge3 GNU C Library: Shared libraries an
ii  libpam0g  0.76-22Pluggable Authentication Modules l

-- debconf information excluded


-- 
To UNSUBSCRIBE, email to [EMAIL PROTECTED]
with a subject of "unsubscribe". Trouble? Contact [EMAIL PROTECTED]