🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: news.software.nntp
Article #84261

Re: New CNFS buffers not reported in daily report after "ctlinnd xexec innd"

#84261
From: Julien ÉLIE
Date: Thu, 11 Aug 2011 18:58
179 lines
6803 bytes
Hi Michael and Russ,

>> Shouldn't we add an option to cnfsstat to reload storage.conf and
>> cycbuff.conf from time to time?  For instance each day by default.  But
>> it could be changed (or disabled) by a flag passed to cnfsstat.
> 
> Yeah, that's what I was thinking.  All it would need to do is check the
> last modification time of those files periodically and reload them
> automatically if they change.
> 
>> The problem is that it could lead to unexpected logs in case the two
>> configuration files are not the right ones to use at the time cnfsstat
>> reloads them.  For instance if the news administrator is modifying them
>> but still has not restarted INN.
> 
> I think it's probably okay to reload them, as long as we don't die if they
> don't exist or have other problems.  I don't think people change their
> configuration and then leave INN running without a restart for extended
> periods of time very often.

Suggested patch follows.

I also changed the "Cannot open CycBuff Conffile" message because it is not
always true.  The message can be logged when an error occurs during its parsing.
Sometimes, even the parsing was incorrect, the file was accepted.  Not good IMHO
so I also changed that to refuse the file at cnfsstat startup.


Index: cnfsstat.in
===================================================================
--- cnfsstat.in	(révision 9281)
+++ cnfsstat.in	(copie de travail)
@@ -22,6 +22,7 @@
 
 my $conffile = "$INN::Config::pathetc/cycbuff.conf";
 my $storageconf = "$INN::Config::pathetc/storage.conf";
+my $lastconftime = 0;
 
 sub usage {
     print <<"_end_";
@@ -44,8 +45,11 @@
     exit(1);
 }
 
-my (%class, %buff, %stor, @storsort, @buffers);
+my (%class, %buff, %stor, @storsort);
+my (%prevclass, %prevbuff, %prevstor, @prevstorsort);
 
+my @buffers;
+
 my ($oclass, $obuffer);
 my %opt = (c=>\$oclass, m=>\$obuffer);
 Getopt::Long::config('no_ignore_case');
@@ -79,12 +83,12 @@
 my $sleeptime = (defined($opt{'l'}) && $opt{'l'} > 0) ? $opt{'l'} : 600;
 
 unless (read_cycbuffconf()) {
-    print STDERR "Cannot open CycBuff Conffile $conffile ...\n";
+    print STDERR "Invalid $conffile file.\n";
     exit (1);
 }
 
 unless (read_storageconf()) {
-    print STDERR "No valid $storageconf.\n";
+    print STDERR "Invalid $storageconf file.\n";
     exit (1);
 }
 
@@ -95,6 +99,46 @@
 
 START:
 
+# Check whether the configuration files need reloading.
+my $cycbufftime = (stat($conffile))[9];
+my $storagetime = (stat($storageconf))[9];
+my $maxtime = ($cycbufftime < $storagetime) ? $storagetime : $cycbufftime;
+
+# Set $lastconftime for the first run of the comparison.
+$lastconftime = $maxtime if not $lastconftime;
+
+if ($lastconftime < $maxtime) {
+    my $reloadok = 1;
+
+    $lastconftime = $maxtime;
+
+    # Save the previous configuration, in case reloading it fails.
+    # Direct copies of the arrays and hashes works fine here.
+    %prevclass = %class; undef %class;
+    %prevbuff = %buff; undef %buff;
+    %prevstor = %stor; undef %stor;
+    @prevstorsort = @storsort; undef @storsort;
+
+    unless (read_cycbuffconf()) {
+        print STDERR "Invalid $conffile file.\n";
+        $reloadok = 0;
+    }
+
+    unless (read_storageconf()) {
+        print STDERR "Invalid $storageconf file.\n";
+        $reloadok = 0;
+    }
+
+    # In case reloading configuration files fails, restore the
+    # previous known configuration for this run of cnfsstat.
+    if (!$reloadok) {
+        %class = %prevclass;
+        %buff = %prevbuff;
+        %stor = %prevstor;
+        @storsort = @prevstorsort;
+    }
+}
+
 my $logline;
 my $header_printed = 0;
 my ($gr, $cl, $min, $max);
@@ -216,13 +260,14 @@
 	    @line = split(/:/, $_);
 	    if ($buff{$line[1]}) {
 		print STDERR "Buff $line[1] more than one time in CycBuff Conffile $conffile ...\n";
-		return 1;
+		return 0;
 	    }
 	    $buff{$line[1]} = $line[2];
 	    next;
 	}
 
 	print STDERR "Unknown config line \"$_\" in CycBuff Conffile $conffile ...\n";
+        return 0;
     }
     close $CONFFILE;
     return 1;




Index: rc.news.pod
===================================================================
--- rc.news.pod	(r?vision 9281)
+++ rc.news.pod	(copie de travail)
@@ -32,7 +32,11 @@
 
 =item *
 
-If I<docnfsstat> is true in F<inn.conf>:  B<ovdb_init> is run;
+If I<docnfsstat> is true in F<inn.conf>:  B<cnfsstat> is started and stopped.
+
+=item *
+
+If I<ovmethod> is set to C<ovdb> in F<inn.conf>:  B<ovdb_init> is run;
 B<ovdb_server> and B<ovdb_monitor> are stopped.
 
 =item *




Index: cnfsstat.pod
===================================================================
--- cnfsstat.pod	(r?vision 9281)
+++ cnfsstat.pod	(copie de travail)
@@ -38,6 +38,10 @@
 and only exits if an error occurs.  When unspecified, the default interval
 is C<600> seconds.
 
+At each iteration, B<cnfsstat> checks whether the F<cycbuff.conf> and
+F<storage.conf> files have been modified, and loads the new configuration
+if needed.
+
 =item B<-m> I<buffer>
 
 Print information about the specified buffer in a format suitable for MRTG.




-- 
Julien ÉLIE

« Sitis licita, etiam potio licita. »
Technical Details
Message-ID: <j218p5$cdi$1@news.trigofacile.com>
Path: mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!illumos!news.pugleaf.net!.TX!archive.pugleaf.net!archive.newsdeef.eu!mbox2nntp-news.software.nntp.20141118.mbox.gz!border1.nntp.dca3.giganews.com!border2.nntp.dca3.giganews.com!border4.nntp.dca.giganews.com!border2.nntp.dca.giganews.com!nntp.giganews.com!goblin3!goblin.stu.neva.ru!gegeweb.org!news.trigofacile.com!.POSTED.aaubervilliers-552-1-67-40.w83-200.abo.wanadoo.fr!not-for-mail
References: <inkvvh$2e4i$1@de-l.enfer-du-nord.net> <87pqoxj4c5.fsf@windlord.stanford.edu> <inl51i$jkh$1@news.trigofacile.com> <87lizlj0fe.fsf@windlord.stanford.edu>

Show Full Headers
Complete Article Headers
Message-ID: <j218p5$cdi$1@news.trigofacile.com>
Subject: Re: New CNFS buffers not reported in daily report after "ctlinnd xexec innd"
Date: Thu, 11 Aug 2011 20:58:45 +0200
From: Julien ÉLIE <iulius@nom-de-mon-site.com.invalid>
References: <inkvvh$2e4i$1@de-l.enfer-du-nord.net> <87pqoxj4c5.fsf@windlord.stanford.edu> <inl51i$jkh$1@news.trigofacile.com> <87lizlj0fe.fsf@windlord.stanford.edu>
Path: mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!illumos!news.pugleaf.net!.TX!archive.pugleaf.net!archive.newsdeef.eu!mbox2nntp-news.software.nntp.20141118.mbox.gz!border1.nntp.dca3.giganews.com!border2.nntp.dca3.giganews.com!border4.nntp.dca.giganews.com!border2.nntp.dca.giganews.com!nntp.giganews.com!goblin3!goblin.stu.neva.ru!gegeweb.org!news.trigofacile.com!.POSTED.aaubervilliers-552-1-67-40.w83-200.abo.wanadoo.fr!not-for-mail
Newsgroups: news.software.nntp
Organization: TrigoFACILE -- http://www.trigofacile.com/
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Injection-Date: Thu, 11 Aug 2011 18:58:46 +0000 (UTC)
Injection-Info: news.trigofacile.com;
 posting-host="aaubervilliers-552-1-67-40.w83-200.abo.wanadoo.fr:83.200.66.40";
 logging-data="12722"; mail-complaints-to="abuse@trigofacile.com"
User-Agent: Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10.7; fr;
In-Reply-To: <87lizlj0fe.fsf@windlord.stanford.edu>
Lines: 178
X-Original-Bytes: 6626