Hi,

Could you please review the attached patch? (It's written against
the svn rev: 2375).

This patch does the following:
* It removes the deletion of the TMPFILE that caused all plugins not
  to be activated, in case one of them raised an error.
* It logs the STDOUT and STDERR to /var/log/munin/munin-node-configure.log
  The log format is the same as the rest of the munin logs in terms of
  date formatting. postinst logs the STDOUT first, and only in case STDERR
  was found, it logs the errors. In order to seperate STDOUT & STDERR I had
  to use an additional TMPFILE, and I also added it to be removed at the
  end of the process.
* Reduced a little bit of duplication in the init_plugins() function.

Regarding filtering the STDOUT for '^ln ' lines, I thought about this and I
think this might cause a problem in case munin-node-configure changes in the
future to output additional commands besides 'ln'. As we know that
munin-node-configure seperates the errors to STDERR and that when given the
--shell option it only outputs relevant commands to STDOUT, I think it's safe
to continue with the way things are today (without filtering ln).

Here's the log that's resulting in installing munin-node with the patch
on my machine:
/var/log/munin/munin-node-configure.log:
---
Aug 27 09:40:23 - Starting munin-node-configure --shell
ln -s /usr/share/munin/plugins/cpu /etc/munin/plugins/cpu
ln -s /usr/share/munin/plugins/entropy /etc/munin/plugins/entropy
ln -s /usr/share/munin/plugins/exim_mailqueue /etc/munin/plugins/exim_mailqueue
ln -s /usr/share/munin/plugins/exim_mailstats /etc/munin/plugins/exim_mailstats
ln -s /usr/share/munin/plugins/forks /etc/munin/plugins/forks
ln -s /usr/share/munin/plugins/if_ /etc/munin/plugins/if_eth0
ln -s /usr/share/munin/plugins/if_err_ /etc/munin/plugins/if_err_eth0
ln -s /usr/share/munin/plugins/interrupts /etc/munin/plugins/interrupts
ln -s /usr/share/munin/plugins/iostat /etc/munin/plugins/iostat
ln -s /usr/share/munin/plugins/irqstats /etc/munin/plugins/irqstats
ln -s /usr/share/munin/plugins/load /etc/munin/plugins/load
ln -s /usr/share/munin/plugins/memory /etc/munin/plugins/memory
ln -s /usr/share/munin/plugins/nfs_client /etc/munin/plugins/nfs_client
ln -s /usr/share/munin/plugins/open_files /etc/munin/plugins/open_files
ln -s /usr/share/munin/plugins/open_inodes /etc/munin/plugins/open_inodes
ln -s /usr/share/munin/plugins/processes /etc/munin/plugins/processes
ln -s /usr/share/munin/plugins/swap /etc/munin/plugins/swap
ln -s /usr/share/munin/plugins/vmstat /etc/munin/plugins/vmstat
The following errors were reported by munin-node-configure --shell
# There were some errors:
# Got junk from df_inode: df: no file systems processed
# Got junk from df_inode: Error executing df. Exit code 256
# Got junk from df: df: no file systems processed
# Got junk from df: Error executing df. Exit code 256
---

Thanks,
Tom
Index: munin-node.postinst
===================================================================
--- munin-node.postinst	(revision 2375)
+++ munin-node.postinst	(working copy)
@@ -28,25 +28,35 @@
 
 init_plugins() {
 	TMPFILE=`mktemp /tmp/munin-node.configure.XXXXXXXXXX`
+	TMPFILE_STDERR=`mktemp /tmp/munin-node.configure.err.XXXXXXXXXX`
+	MUNIN_NODE_CONF_LOG="/var/log/munin/munin-node-configure.log"
 	if [ "$prevver" ]; then
+		MUNIN_NODE_CMD="munin-node-configure --shell --newer "${prevver%-*}""    
 		echo -n "Initializing new plugins.."
-		munin-node-configure --shell --newer "${prevver%-*}" > $TMPFILE || rm -f $TMPFILE
-		if [ -f $TMPFILE ] ; then 
-			sh < $TMPFILE  
-		else
-			echo "failed."
-		fi
 	else
+		MUNIN_NODE_CMD="munin-node-configure --shell"
 		echo -n "Initializing plugins.."
-		munin-node-configure --shell > $TMPFILE || rm -f $TMPFILE
-		if [ -f $TMPFILE ] ; then
-			sh < $TMPFILE
-		else 
-			echo "failed."
-		fi
+    fi
+
+	# munin-node-conf returns 1 if case of partial plugin autoconf
+	# errors. We need to ignore these errors as even one plugin
+	# can fail the entire process. See Debian bug #539886 for details.
+	$MUNIN_NODE_CMD 2>$TMPFILE_STDERR >$TMPFILE || true
+	if [ -f $TMPFILE ]; then
+		DATE=`date '+%b %d %T'`
+		echo "$DATE - Starting $MUNIN_NODE_CMD" >> $MUNIN_NODE_CONF_LOG
+		cat $TMPFILE >> $MUNIN_NODE_CONF_LOG
+        if [ -s $TMPFILE_STDERR ]; then
+			echo "The following errors were reported by $MUNIN_NODE_CMD" \
+			>> $MUNIN_NODE_CONF_LOG 
+			cat $TMPFILE_STDERR >> $MUNIN_NODE_CONF_LOG
+        fi
+		sh < $TMPFILE
+	else 
+		echo "failed."
 	fi
 	echo "done."
-	rm -f $TMPFILE
+	rm -f $TMPFILE $TMPFILE_STDERR
 	echo -n "Restarting munin-node.."
 	invoke-rc.d munin-node restart
 }

Reply via email to