[Opendnssec-commits] [keihatsu.kirei.se/svn/dnssec] r4160 - trunk/monitor/lib

Alex Dalitz alexd at nominet.org.uk
Tue Nov 2 10:38:29 CET 2010


Author: alex
Date: 2010-11-02 10:38:29 +0100 (Tue, 02 Nov 2010)
New Revision: 4160

Modified:
   trunk/monitor/lib/nagios_cache.rb
Log:
Introducing lock file to cache checker to ensure only one monitor process pokes unbound at a time- fixes race hazard when multiple NAGIOS instances all run one instance of monitor and unbound

Modified: trunk/monitor/lib/nagios_cache.rb
===================================================================
--- trunk/monitor/lib/nagios_cache.rb	2010-11-01 16:12:41 UTC (rev 4159)
+++ trunk/monitor/lib/nagios_cache.rb	2010-11-02 09:38:29 UTC (rev 4160)
@@ -46,6 +46,7 @@
 include Dnsruby
 
 CACHE_FILE = "/var/tmp/cache.old"
+LOCK_FILE = "/var/tmp/cache.lock"
 
 
 class CacheCheckerOptionsParser
@@ -152,6 +153,7 @@
     return nil
   rescue Exception => e
     print "CACHECHECKER CRITICAL: Error sending validation query : #{e}\n"
+    unlock
     exit(2)
   end
 end
@@ -165,6 +167,20 @@
   return s
 end
 
+def sort_locks
+  # Check the lock file - if it's there then exit critical
+  if (File.exist?LOCK_FILE)
+    print "CACHECHECKER CRTICAL: Lock-file (#{LOCK_FILE}) present from other process\n"
+    exit(3)
+  end
+  # Create the lock file
+  File.open(LOCK_FILE, "w") {}
+end
+
+def unlock
+  File.delete(LOCK_FILE)
+end
+
 def send_unbound(msg, options)
   #  addr, port = options.nameserver
   s = get_unbound_command_start(options)
@@ -198,6 +214,7 @@
   print "CACHECHECKER CRITICAL: No name and type to check\n"
   exit(3)
 end
+sort_locks
 # Create the Resolver object from options.nameserver
 addr, port = options.nameserver
 #print "Making resolver\n"
@@ -213,9 +230,15 @@
   "KSK Rollover : DNSKEY but no DS records in cache" => [Types.DS]
 }
 # Check if cache.old exists - if it doesn't, then quickly create it
+begin
 if (File.exist?("#{CACHE_FILE}"))
   File.delete("#{CACHE_FILE}")
 end
+rescue Error => e
+  unlock
+  print "CACHECHECKER CRITICAL: Can't delete cache file #{CACHE_FILE}\n"
+  exit(3)
+end
 dump_cache(res, options)
 #print "Starting tests\n"
 count = 0
@@ -240,7 +263,7 @@
   end
 
   # Then, delete the RRSets we want to delete
-#    print "Setting up for : #{test}\n"
+  #    print "Setting up for : #{test}\n"
   rrs_to_wipe.each { |type|
     if (type == Types.RRSIG)
       # We want to wipe the RRSIG for a specific name and type.
@@ -251,7 +274,7 @@
       send_unbound("flush_type #{options.zone} #{type.string}", options)
     end
   }
-#  system "unbound-control dump_cache"
+  #  system "unbound-control dump_cache"
   # Then, send the validation query
   error = send_query(res, options)
   # And collect any errors
@@ -259,6 +282,7 @@
   count += 1
 }
 dump_cache(res, options)
+unlock
 if (errors.length == 0)
   print "CACHECHECKER OK: All rollover scenarios checked\n"
   exit(0)




More information about the Opendnssec-commits mailing list