[Popcon-commits] cvs commit to popularity-contest/debian by ballombe

ballombe at cvs.alioth.debian.org ballombe at cvs.alioth.debian.org
Wed May 7 16:50:23 UTC 2008


Update of /cvsroot/popcon/popularity-contest/debian
In directory alioth:/tmp/cvs-serv21139/debian

Modified Files:
	changelog postinst preinst 
Added Files:
	cron.daily 
Removed Files:
	cron.weekly 
Log Message:
Instead of reporting on Sunday, now a random day in the week is 
chosen. This spread the load on the server. Closes: #440493, #459910.


Index: changelog
===================================================================
RCS file: /cvsroot/popcon/popularity-contest/debian/changelog,v
retrieving revision 1.388
retrieving revision 1.389
diff -u -d -r1.388 -r1.389
--- changelog	5 May 2008 20:02:45 -0000	1.388
+++ changelog	7 May 2008 16:50:21 -0000	1.389
@@ -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
 

--- NEW FILE: cron.daily ---
#!/bin/sh

# don't run if this package is removed but not purged
if [ ! -f /usr/sbin/popularity-contest ]; then
	exit 0
fi

unset MAILFROM
unset MAILTO
unset MY_HOSTID
unset PARTICIPATE
unset SUBMITURLS
unset USEHTTP

# get configuration information
. /usr/share/popularity-contest/default.conf
. /etc/popularity-contest.conf

# don't run if MAILTO address is blank, and not configured to use HTTP POST!
if [ -z "$MAILTO" ] && [ "yes" != "$USEHTTP" ]; then exit 0; fi

# don't run if PARTICIPATE is "no" or unset!
[ "$PARTICIPATE" = "no" ] || [ -z "$PARTICIPATE" ] && exit 0

if [ -n "$HTTP_PROXY" ]; then
  export http_proxy="$HTTP_PROXY";
fi

# Only run on the given day, to spread the load on the server a bit
if [ "$DAY" ] && [ "$DAY" != "$(date +%w)" ] ; then
  exit 0
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
}

do_sendmail()
{
	if [ -n "$MAILFROM" ]; then
		sendmail -oi -f "$MAILFROM" $MAILTO
	else
		sendmail -oi $MAILTO
	fi
}

# generate the popularity contest data

run_popcon > $POPCON

SUBMITTED=no

# try to post the report through http POST
if [ "$SUBMITURLS" ] && [ "yes" = "$USEHTTP" ]; then
    for URL in $SUBMITURLS ; do
	if setsid /usr/share/popularity-contest/popcon-upload \
	    -u $URL -f $POPCON 2>/dev/null ; then
		SUBMITTED=yes
	else
		logger -t popularity-contest "unable to submit report to $URL."
	fi
    done
fi

# try to email the popularity contest data

if [ yes != "$SUBMITTED" ] && [ "$MAILTO" ]; then
    if [ -x "`which sendmail 2>/dev/null`" ]; then
	(
	    if [ -n "$MAILFROM" ]; then
	        	echo "From: <$MAILFROM>"
	    	echo "Sender: <$MAILFROM>"
	    fi
	    echo "To: $MAILTO"
	    echo "Subject: popularity-contest submission"
	    echo "MIME-Version: 1.0"
	    echo "Content-Type: text/plain"
	    echo
	    cat $POPCON
	) | do_sendmail
	SUBMITTED=yes
    else
	logger -t popularity-contest "unable to submit report using sendmail."
    fi
fi

if [ "yes" != "$SUBMITTED" ] ; then
	logger -t popularity-contest "unable to submit report."
fi

--- cron.weekly DELETED ---

Index: postinst
===================================================================
RCS file: /cvsroot/popcon/popularity-contest/debian/postinst,v
retrieving revision 1.19
retrieving revision 1.20
diff -u -d -r1.19 -r1.20
--- postinst	29 Oct 2006 08:58:26 -0000	1.19
+++ postinst	7 May 2008 16:50:21 -0000	1.20
@@ -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: preinst
===================================================================
RCS file: /cvsroot/popcon/popularity-contest/debian/preinst,v
retrieving revision 1.1.1.1
retrieving revision 1.2
diff -u -d -r1.1.1.1 -r1.2
--- preinst	7 Sep 2003 17:27:27 -0000	1.1.1.1
+++ preinst	7 May 2008 16:50:21 -0000	1.2
@@ -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-commits mailing list