[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Debian JP master SVN www commits (rev.876)



=======================================================
Repository: /org/svn.debian.or.jp/repos
  Revision: 876
  Commiter: yasu
      Date: 2009-04-13 16:27:09 +0900 (月, 13  4月 2009)
=======================================================
Log:

you can use SIGHUP

=======================================================
Changed:

U   cdn/trunk/DNS-Balance/ChangeLog
U   cdn/trunk/DNS-Balance/dns_balance.rb

Modified: cdn/trunk/DNS-Balance/ChangeLog
===================================================================
--- cdn/trunk/DNS-Balance/ChangeLog	2009-04-13 06:16:35 UTC (rev 875)
+++ cdn/trunk/DNS-Balance/ChangeLog	2009-04-13 07:27:09 UTC (rev 876)
@@ -1,3 +1,7 @@
+2009-04-13  ARAKI Yasuhiro  <araki@xxxxxx>
+
+	* dns_balance.rb (srun): Support SIGHUP. When SIGHUP is received, /var/log/dns_balance.log is renewed. Please set owner and group of "/var/log/dns_balance.log" to "nobody (65534)".
+
 2009-04-10  ARAKI Yasuhiro  <ar@debian.org>
 
 	* dns_balance.rb (select_namespace): Change: Default surrogates are select from NorthAmerica.

Modified: cdn/trunk/DNS-Balance/dns_balance.rb
===================================================================
--- cdn/trunk/DNS-Balance/dns_balance.rb	2009-04-13 06:16:35 UTC (rev 875)
+++ cdn/trunk/DNS-Balance/dns_balance.rb	2009-04-13 07:27:09 UTC (rev 876)
@@ -250,7 +250,7 @@
   #
   # アドレスデータベースの動的更新
   #
-  Thread::start {
+  $t_db = Thread::start {
     loop {
       if test(?r, PREFIX + "/addr") || test(?r, "./addr")
         begin
@@ -271,26 +271,28 @@
     }
   }
 
+    $gs = UDPSocket::new()
+    sockaddr = (if OPT["i"] == nil then Socket::INADDR_ANY else OPT["i"] end)
+    if OPT["port"]
+      $gs.bind(sockaddr, OPT["port"])
+    else
+      $gs.bind(sockaddr, Service::Domain)
+    end
+    begin
+      Process::UID.eid=65534
+    rescue
+      puts $!
+      puts "run by uid #{Process.euid}"
+    end
 
-  gs = UDPSocket::new()
-  sockaddr = (if OPT["i"] == nil then Socket::INADDR_ANY else OPT["i"] end)
-  if OPT["port"]
-    gs.bind(sockaddr, OPT["port"])
-  else
-    gs.bind(sockaddr, Service::Domain)
-  end
-  begin
-    Process::UID.eid=65534
-  rescue
-    puts $!
-    puts "run by uid #{Process.euid}"
-  end
+
   #
   # メインループ
   #
   loop {
-    (packet, client) = gs.recvfrom(1024)
-    Thread.start {
+    (packet, client) = $gs.recvfrom(1024)
+
+    $t_resolv = Thread.start {
       $SAFE = 2
       begin
         client_data = get_client_data(client)
@@ -394,7 +396,7 @@
       #print r.dump, "\n"
       #p q
 
-      gs.send(r, 0, client_data["addr"], client_data["port"])
+      $gs.send(r, 0, client_data["addr"], client_data["port"])
 
       logger(ML, client_data["addr"], status, name, namespace, ans_addrs)
 
@@ -461,41 +463,61 @@
 
 ML = MultiLog::new
 
+def srun
+  if OPT["unfork"]
+    if OPT["logfile"]
+      fd = open($logfile, "w")
+      ML.open(fd)
+    else
+      ML.open
+    end
+    ML.log("dir: " + PREFIX)
+    ML.log("start")
+    print "Start #{$0} running in Foreground mode.\n"
+    run
+  else
+    fd = open($logfile, "w")
+    File.chown(65534,65534,$logfile)
 
-if OPT["unfork"]
-  if OPT["logfile"]
-    fd = open($logfile, "w")
     ML.open(fd)
-  else
-    ML.open
-  end
-  ML.log("dir: " + PREFIX)
-  ML.log("start")
-  print "Start #{$0} running in Foreground mode.\n"
-  run
-else
-  fd = open($logfile, "w")
-  ML.open(fd)
-  ML.log("dir: " + PREFIX)
-  ML.log("start")
-  Process.fork do
-    if File.exist?($process_file)
-      print "Other daemon running. pidfile is #{$process_file}\n"
-      old_pid = File.open($process_file).read.chomp.to_i
-      exit 1
-      fail
+    ML.log("dir: " + PREFIX)
+    ML.log("start")
+    Process.fork do
+      if File.exist?($process_file)
+        print "Other daemon running. pidfile is #{$process_file}\n"
+        old_pid = File.open($process_file).read.chomp.to_i
+        exit 1
+        fail
+      end
+      pid = Process.setsid
+      print "Start #{$0} running pid is #{pid}\n"
+      pidfile = open($process_file, "w+")
+      pidfile.write(pid)
+      pidfile.flush
+      trap("SIGINT"){ exit! 0 }
+      trap("SIGTERM"){ exit! 0 }
+
+#      [ STDIN, STDOUT, STDERR ].each do |io|
+      [ STDIN, STDOUT ].each do |io|
+        io.reopen("/dev/null", "r+")
+      end
+      run
     end
-    pid = Process.setsid
-    print "Start #{$0} running pid is #{pid}\n"
-    pidfile = open($process_file, "w+")
-    pidfile.write(pid)
-    pidfile.flush
-    trap("SIGINT"){ exit! 0 }
-    trap("SIGTERM"){ exit! 0 }
-    trap("SIGHUP"){ exit! 0 }
-    [ STDIN, STDOUT, STDERR ].each do |io|
-      io.reopen("/dev/null", "r+")
-    end
-    run
   end
-end
+
+end ## srun
+
+trap("SIGHUP"){
+  ML.log("SIGHUP")
+  begin
+    Thread.kill $t_db
+    Thread.kill $t_resolv
+  rescue
+    p $!
+  end
+  ML.log("close")
+  ML.close
+  srun
+}
+
+srun