[Popcon-developers] [patch] switch to cron.daily

Bill Allombert Bill.Allombert at math.u-bordeaux1.fr
Mon May 5 21:25:08 UTC 2008


Hello Petter,

The following patch (and mv debian/cron.weekly debian/cron.daily)
extend your patch to fully implement the migration to debian/cron.daily.

/etc/cron.weekly/popularity-contest is moved entirely in the preinst.

This way, if the user modified /etc/cron.weekly/popularity-contest,
then dpkg will prompt them and show them the difference which will
include the lines

# Only run on the given day, to spread the load on the server a bit
if [ "$DAY" ] && [ "$DAY" != "$(date +%w)" ] ; then
  exit 0
fi
(avoiding popcon to report every day)

If they did not modify /etc/cron.weekly/popularity-contest, they will
not be prompted.

Cheers,
-- 
Bill. <ballombe at debian.org>

Imagine a large red swirl here. 
-------------- next part --------------
? debian/popularity-contest
? debian/popularity-contest.debhelper.log
? debian/popularity-contest.postrm.debhelper
? debian/popularity-contest.substvars
Index: FAQ
===================================================================
RCS file: /cvsroot/popcon/popularity-contest/FAQ,v
retrieving revision 1.16
diff -u -r1.16 FAQ
--- FAQ	8 Jan 2008 17:01:43 -0000	1.16
+++ FAQ	5 May 2008 21:18:12 -0000
@@ -53,13 +53,14 @@
 
 Q) When does popularity-contest run ?
 
-A) popularity-contest is run by the weekly cron job 
-   "/etc/cron.weekly/popularity-contest".
-
-Under the default configuration of cron, this happens every Sunday
-at 6:47 in the morning. This can be changed by editing /etc/crontab
-but if your computer is not always turned on, we really recommend you
-install the anacron package.
+A) popularity-contest is run by the daily cron job 
+"/etc/cron.daily/popularity-contest", but only one day in the week,
+whci is specified in the configuration file. This day is chosen randomly
+to spread the load on the server.
+
+Under the default configuration of cron, this happens at 6:47 in the morning.
+This can be changed by editing /etc/crontab but if your computer is not always
+turned on, we really recommend you install the anacron package.
 
 Q) I don't want popcon email to be sent by root! How can I change that ?
 
Index: debian/changelog
===================================================================
RCS file: /cvsroot/popcon/popularity-contest/debian/changelog,v
retrieving revision 1.388
diff -u -r1.388 changelog
--- debian/changelog	5 May 2008 20:02:45 -0000	1.388
+++ debian/changelog	5 May 2008 21:18:12 -0000
@@ -8,6 +8,8 @@
     - revert changes introduced in 1.44.
     - Use :encoding(UTF-8) instead of :utf8 when reapding packages files
     - Add query box linking to <http://qa.debian.org/popcon.php>
+  * Instead of reporting on Sunday, now a random day in the week is 
+    chosen. This spread the load on the server. Closes: #440493, #459910.
 
  -- Bill Allombert <ballombe at debian.org>  Mon, 05 May 2008 22:00:55 +0200
 
Index: debian/postinst
===================================================================
RCS file: /cvsroot/popcon/popularity-contest/debian/postinst,v
retrieving revision 1.19
diff -u -r1.19 postinst
--- debian/postinst	29 Oct 2006 08:58:26 -0000	1.19
+++ debian/postinst	5 May 2008 21:18:12 -0000
@@ -34,8 +34,14 @@
         fi
 }
 
+# Select a random day to submit on, to spread the load over time, unless it is already set.
+select_random_day() {
+        DAY=`bash -c 'echo $(($RANDOM % 7))'`
+}
+
 generate_conffile() {
         generate_id
+	select_random_day
 	cat <<-EOF >$conffile
 		# Config file for Debian's popularity-contest package.
 		#
@@ -50,6 +56,7 @@
 		MY_HOSTID="$MY_HOSTID"
 		PARTICIPATE="$PARTICIPATE"
 		USEHTTP="yes"
+		DAY="$DAY"
 	EOF
 
 	# preseeding is only allowed on first time install
@@ -77,6 +84,13 @@
             # of behaviour with stdin. version 1.17, 2004-04-12.
               *-)  MY_HOSTID="${MY_HOSTID%  -}";;
             esac;
+
+	    # If DAY is not set, add it.
+	    if [ -z "$DAY" ] ; then
+	        select_random_day
+	        echo "DAY=\"$DAY\"" >> $conffile
+	    fi
+
 	    # Replace only if the content changed, to avoid changing the
 	    # config file date when no change was done.
 
Index: debian/preinst
===================================================================
RCS file: /cvsroot/popcon/popularity-contest/debian/preinst,v
retrieving revision 1.1.1.1
diff -u -r1.1.1.1 preinst
--- debian/preinst	7 Sep 2003 17:27:27 -0000	1.1.1.1
+++ debian/preinst	5 May 2008 21:18:12 -0000
@@ -1,10 +1,23 @@
 #!/bin/sh
 
+case "$1" in
+install|upgrade)
+# Move a conffile without triggering a dpkg question if it was not modified.
+    if dpkg --compare-versions "$2" le "1.44"; then
+      PKGNAME="popularity-contest"
+      CONFFILE="/etc/cron.weekly/popularity-contest"
+      NEWCONFFILE="/etc/cron.daily/popularity-contest"
+      if [ -e "$CONFFILE" ]; then
+          md5sum="`md5sum \"$CONFFILE\" | sed -e \"s/ .*//\"`"
+          old_md5sum="`dpkg-query -W -f='${Conffiles}' $PKGNAME | sed -n -e \"\\\\' $CONFFILE '{s/ obsolete$//;s/.* //p}\"`"
+          if [ "$md5sum" = "$old_md5sum" ]; then
+              rm -f "$CONFFILE"
+          else
+              mv -f "$CONFFILE" "$NEWCONFFILE"
+          fi
+      fi
+    fi
+esac
+
 #DEBHELPER#
 
-# older versions had popularity-contest as a conffile in a different dir, so
-# it won't get removed automatically.
-#
-if [ "$1" = upgrade ]; then
-    rm -f /etc/cron.daily/popularity-contest
-fi


More information about the Popcon-developers mailing list