[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

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



tags 610876 patch
thanks

On Sun, Jan 23, 2011 at 05:35:08PM +0100, Alberto Aparici wrote:
> Popularity-contest is intended to be run approximately once a week. Its 
...snip...
> But even this has a problem: some computers may not run 7 days
> a week. A computer that only runs, for example, on weekends, and ends 
> up with DAY="3" will never run the popularity contest, not even with
> anacron, because anacron will execute the popularity-contest script
> but it will exit without running the contest, as it's not Wednesday :-(

here's a patch that checks the last time /var/log/popularity-contest was
updated, and exits if it was updated more recently than a week ago:

diff -U 5  debian/cron.daily.orig  debian/cron.daily
--- debian/cron.daily.orig      2011-03-06 08:26:52.000000000 -0800
+++ debian/cron.daily   2011-03-06 08:57:43.000000000 -0800
@@ -29,15 +29,25 @@
 # Only run on the given day, to spread the load on the server a bit
 if [ "$DAY" ] && [ "$DAY" != "$(date +%w)" ] ; then
   exit 0
 fi

+POPCON=/var/log/popularity-contest
+if [ -z "$DAY" ] && [ -f "$POPCON" ] ; then
+    now=$(date +%s)
+    lastrun=$(date -r $POPCON +%s)
+    # one week, in seconds
+    week=604800
+    if [ "$(( $now - $lastrun ))" -le "$week" ]; then
+        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()
 {
        su -s /bin/sh -c "/usr/sbin/popularity-contest" nobody
 }


it relies on the un-setting DAY in /etc/popularity-contest.conf, though maybe
it would make sense to make it the default (by not setting DAY= in postinst)?
that would make the first time cron.daily runs the effective day of week to run
popularity-contest, rather than randomly selecting a day, while working
reasonably sanely on machines that aren't always on.


live well,
  vagrant





Reply to: