From 69c28efc768e22029ba343f335dd198ac52b1eef Mon Sep 17 00:00:00 2001 From: Michael Vogt Date: Mon, 25 Feb 2008 18:08:19 +0000 Subject: * debian/apt.cron.daily: - sleep random amount of time (default within 0-30min) before starting the upate to hit the mirrors less hard --- debian/apt.cron.daily | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) (limited to 'debian/apt.cron.daily') diff --git a/debian/apt.cron.daily b/debian/apt.cron.daily index 7af689e1f..ec53a7f2f 100644 --- a/debian/apt.cron.daily +++ b/debian/apt.cron.daily @@ -147,6 +147,25 @@ check_size_constraints() fi } +# sleep for a random intervall of time (default 30min) +# (some code taken from cron-apt, thanks) +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 +} + +# main + if ! which apt-config >/dev/null; then exit 0 fi @@ -179,6 +198,13 @@ if ! apt-get check -q -q 2>/dev/null; then exit 1 fi +# sleep random amount of time +random_sleep + +# check again if we can access the cache +if ! apt-get check -q -q 2>/dev/null; then + exit 1 +fi UPDATE_STAMP=/var/lib/apt/periodic/update-stamp if check_stamp $UPDATE_STAMP $UpdateInterval; then -- cgit v1.2.3-70-g09d2 From 626a8c601bf1179f6d332337d01e527c008cfe78 Mon Sep 17 00:00:00 2001 From: Otavio Salvador Date: Fri, 2 May 2008 12:16:41 -0300 Subject: Make cron script quiet if cache is locked. Closes: #459344 --- debian/apt.cron.daily | 5 +++-- debian/changelog | 2 ++ 2 files changed, 5 insertions(+), 2 deletions(-) (limited to 'debian/apt.cron.daily') diff --git a/debian/apt.cron.daily b/debian/apt.cron.daily index ec53a7f2f..1ca830c93 100644 --- a/debian/apt.cron.daily +++ b/debian/apt.cron.daily @@ -193,9 +193,10 @@ if which on_ac_power >/dev/null; then fi # check if we can lock the cache and if the cache is clean +# There's a reasonable chance that someone is already running an apt +# frontend that has locked the cache, so exit quietly if it is locked. if ! apt-get check -q -q 2>/dev/null; then - echo "$0: could not lock the APT cache" - exit 1 + exit 0 fi # sleep random amount of time diff --git a/debian/changelog b/debian/changelog index cba6920eb..5728af419 100644 --- a/debian/changelog +++ b/debian/changelog @@ -2,6 +2,8 @@ apt (0.7.13) UNRELEASED; urgency=low * Add missing build-depends back from build-depends-indep field. Closes: #478231 + * Make cron script quiet if cache is locked. Thanks to Ted Percival + for the patch. Closes: #459344 -- Otavio Salvador Fri, 02 May 2008 12:07:08 -0300 -- cgit v1.2.3-70-g09d2