[Popcon-developers] Bug#610876: popularity-contest: Popularity contest will not be run in certain machines due to the DAY variable

Vagrant Cascadian vagrant at debian.org
Sat Mar 12 17:27:22 UTC 2011


On Mon, Mar 07, 2011 at 12:33:16PM +0100, Bill Allombert wrote:
> Is your patch valid with /bin/sh being dash ?

i don't see anything that would be a problem...  i haven't actually tested the
code, but i've used all the constructs in dash scripts in the past without
problem. is there something specific that you're wondering about?
 
 
> This is an interesting suggestion. Maybe we would change the script to:
> 1) always try to report on DAY.
> 2) always try to report if /var/log/popularity-contest is more that 7 days old.
> 
> Using the first time cron.daily runs as the reporting day unsufficiently
> random, especially with clusters.

the following updated patch should mostly address those concerns (and an
inverted less-than/greater-than issue). it will cause it to run once on the
first cron.daily run after install, but after that respect the DAY variable:

--- cron.daily.orig	2011-03-06 08:26:52.000000000 -0800
+++ cron.daily	2011-03-12 08:52:31.000000000 -0800
@@ -26,16 +26,26 @@
   export http_proxy="$HTTP_PROXY";
 fi
 
+POPCON=/var/log/popularity-contest
+
 # Only run on the given day, to spread the load on the server a bit
 if [ "$DAY" ] && [ "$DAY" != "$(date +%w)" ] ; then
-  exit 0
+	# Ensure that popcon runs at least once in the last week
+	if [ -f "$POPCON" ] ; then
+		now=$(date +%s)
+		lastrun=$(date -r $POPCON +%s)
+		# one week, in seconds
+		week=604800
+		if [ "$(( $now - $lastrun ))" -ge "$week" ]; then
+			exit 0
+		fi
+	fi
 fi
 
 # keep old logs
 cd /var/log
 umask 022
 savelog -c 7 popularity-contest >/dev/null
-POPCON=/var/log/popularity-contest
 
 run_popcon()
 {
 

an alternate approach would be to simply touch $POPCON on the first cron.daily
run, though you might miss the first week of popcon data if it happens to be
offline or without network on $DAY:

--- cron.daily.orig	2011-03-06 08:26:52.000000000 -0800
+++ cron.daily	2011-03-12 09:02:00.000000000 -0800
@@ -26,16 +26,29 @@
   export http_proxy="$HTTP_PROXY";
 fi
 
+POPCON=/var/log/popularity-contest
+
 # Only run on the given day, to spread the load on the server a bit
 if [ "$DAY" ] && [ "$DAY" != "$(date +%w)" ] ; then
-  exit 0
+	# Ensure that popcon runs at least once in the last week
+	if [ -f "$POPCON" ] ; then
+		now=$(date +%s)
+		lastrun=$(date -r $POPCON +%s)
+		# one week, in seconds
+		week=604800
+		if [ "$(( $now - $lastrun ))" -ge "$week" ]; then
+			exit 0
+		fi
+    else
+        touch $POPCON
+        exit 0
+	fi
 fi
 
 # keep old logs
 cd /var/log
 umask 022
 savelog -c 7 popularity-contest >/dev/null
-POPCON=/var/log/popularity-contest
 
 run_popcon()
 {


could probably come up with something more complicated that handles the corner
cases more perfectly, but it might not be worth the code complexity.

both patches might need some fiddling with the value of week in seconds, since
simply running popcon might take longer than a second; you might end up
consistantly running every 8 days (for machines that don't typically run on
$DAY).  subtracting a few hours (5-12?) from the week variable might be the
simplest way to handle that.


i wish i had followed up on this idea in time for lenny (yes, lenny) release...
heh. :)


live well,
  vagrant





More information about the Popcon-developers mailing list