/etc/cron.daily/apt hangs [solved]

Daevid Vincent daevid at daevid.com
Mon Feb 23 21:31:49 UTC 2009


On Mon, 2009-02-23 at 21:07 +0100, Markus Schönhaber wrote:

> Daevid Vincent:
> 
> > If I try to run /etc/cron.daily/apt, it just hangs.
> [...]
> > stat64("/bin/sleep", {st_mode=S_IFREG|0755, st_size=26060, ...}) = 0
> > clone(child_stack=0, flags=CLONE_CHILD_CLEARTID|CLONE_CHILD_SETTID|
> > SIGCHLD, child_tidptr=0xb7e22908) = 16082
> > wait4(-1,
> 
> Looks pretty normal to me. Among the first things the apt script does is to 
> sleep for a random amount of time.

So when I expect all my cron.daily tasks to be running at a given time
in crontab, they're actually all delayed by some random amount. Since
it's name is alphabetically earlier than anything else in the directory,
this 'apt' holds up all the scripts below as they're not fired off in
threads. *sigh*

> If you check the process list, you'll probably see that there's a "sleep" 
> process that was started by the script - something that the above output from 
> strace also indicates.


I see that code:

# sleep for a random intervall of time (default 30min)
random_sleep()
{
    RandomSleep=1800
    eval $(apt-config shell RandomSleep APT::Periodic::RandomSleep)
    if [ $RandomSleep -eq 0 ]; then
	return
    fi
    if [ -z "$RANDOM" ] ; then
        # A fix for shells that do not have this bash feature.
	RANDOM=$(dd if=/dev/urandom count=1 2> /dev/null | cksum | cut -c"1-5")
    fi
    TIME=$(($RANDOM % $RandomSleep))
    sleep $TIME
}

I tried this on my home and work machine and can confirm you're
correct. 

root at daevid:/etc/cron.daily# date;./apt;date
Mon Feb 23 13:07:56 PST 2009
Mon Feb 23 13:16:58 PST 2009

I did some research and found this:
http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=483177

"The random sleep was added to avoid that the big archive
servers/mirrors get hammered at exactly the same time when a lot of
machines are switched on, e.g. 9:00 in the morning. '

Who "switches on" a Unix box??! They normally are running 24/7 right?

root:~$ cat /etc/crontab 
# m h dom mon dow user	command
17 *	* * *	root    cd / && run-parts --report /etc/cron.hourly
25 6	* * *	root	test -x /usr/sbin/anacron || ( cd / && run-parts
--report /etc/cron.daily )
47 6	* * 7	root	test -x /usr/sbin/anacron || ( cd / && run-parts
--report /etc/cron.weekly )
52 6	1 * *	root	test -x /usr/sbin/anacron || ( cd / && run-parts
--report /etc/cron.monthly )

Shows that this is run at 06:25am every day. My work box has the same. 
Wouldn't it have made more sense to just randomize this upon install?

I'm just going to change mine to be:

10 *	* * *	root    cd / && run-parts --report /etc/cron.hourly
30 5	* * *	root	test -x /usr/sbin/anacron || ( cd / && run-parts
--report /etc/cron.daily )
30 6	* * 7	root	test -x /usr/sbin/anacron || ( cd / && run-parts
--report /etc/cron.weekly )
30 7	1 * *	root	test -x /usr/sbin/anacron || ( cd / && run-parts
--report /etc/cron.monthly )

and modify the "apt" script to be:  RandomSleep=300


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.ubuntu.com/archives/ubuntu-users/attachments/20090223/806f9e13/attachment.html>


More information about the ubuntu-users mailing list