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

Debian JP master SVN www commits (rev.1001)



=======================================================
Repository: /org/svn.debian.or.jp/repos
  Revision: 1001
  Commiter: yasu
      Date: 2010-02-11 15:12:04 +0900 (木, 11  2月 2010)
=======================================================
Log:

jaist preference is no1 in Japan.

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

U   cdn/trunk/DNS-Balance/ChangeLog
U   cdn/trunk/DNS-Balance/dns_balance.rb
U   cdn/trunk/country/JPN_deb_cdn_araki_net.rb
U   cdn/trunk/country/JPN_jp_cdn_araki_net.rb
U   cdn/trunk/country_by_hand/JPN_deb_cdn_araki_net.rb
U   cdn/trunk/country_by_hand/JPN_jp_cdn_araki_net.rb
U   cdn/trunk/keepd/keepd.rb
U   cdn/trunk/keepd/test-keepd.rb

Modified: cdn/trunk/DNS-Balance/ChangeLog
===================================================================
--- cdn/trunk/DNS-Balance/ChangeLog	2010-02-06 14:48:21 UTC (rev 1000)
+++ cdn/trunk/DNS-Balance/ChangeLog	2010-02-11 06:12:04 UTC (rev 1001)
@@ -1,3 +1,7 @@
+2009-08-08  ARAKI Yasuhiro  <ar@debian.org>
+
+	* dns_balance.rb (#run): Fix to apply JRuby. At JRuby, Type is important for UDPSocket::new.bind(Sting a, Fixnum b).
+
 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)".

Modified: cdn/trunk/DNS-Balance/dns_balance.rb
===================================================================
--- cdn/trunk/DNS-Balance/dns_balance.rb	2010-02-06 14:48:21 UTC (rev 1000)
+++ cdn/trunk/DNS-Balance/dns_balance.rb	2010-02-11 06:12:04 UTC (rev 1001)
@@ -1,4 +1,5 @@
 #!/usr/bin/ruby
+# -*- coding: euc-jp -*-
 #
 # DNS Balance --- 動的負荷分散を行なう DNS サーバ
 #
@@ -273,8 +274,10 @@
 
     $gs = UDPSocket::new()
     sockaddr = (if OPT["i"] == nil then Socket::INADDR_ANY else OPT["i"] end)
+    sockaddr = '0.0.0.0' if sockaddr == 0
+
     if OPT["port"]
-      $gs.bind(sockaddr, OPT["port"])
+      $gs.bind(sockaddr, OPT["port"].to_i)
     else
       $gs.bind(sockaddr, Service::Domain)
     end

Modified: cdn/trunk/country/JPN_deb_cdn_araki_net.rb
===================================================================
--- cdn/trunk/country/JPN_deb_cdn_araki_net.rb	2010-02-06 14:48:21 UTC (rev 1000)
+++ cdn/trunk/country/JPN_deb_cdn_araki_net.rb	2010-02-11 06:12:04 UTC (rev 1001)
@@ -2,14 +2,14 @@
 $first_surrogate = '61.115.118.67'
 
 $surrogates = {
-  '203.178.137.175' => '9000', # naist
-  '150.65.7.130' => '9', # jaist
+#  '203.178.137.175' => '9000', # naist
+  '150.65.7.130' => '10', # jaist
   '61.115.118.67' => '1000', # hanzubon 2007apr5
-  '210.157.158.38' => '9900', # plat
+#  '210.157.158.38' => '9900', # plat
   '202.229.186.27' => '50', # topstudio
-  '133.5.166.3' => '10', # dennou-q.gfd-dennou.org
-  '130.54.59.159' => '10', # dennou-k.gfd-dennou.org
-  '133.87.45.30' => '10', # dennou-h.gfd-dennou.org
+  '133.5.166.3' => '20', # dennou-q.gfd-dennou.org
+  '130.54.59.159' => '20', # dennou-k.gfd-dennou.org
+  '133.87.45.30' => '40', # dennou-h.gfd-dennou.org
   '61.206.119.174' => '20', # oyu-net.jp
   '203.141.150.38' => '20', # mirrors.nemui.org
 ##  '219.111.15.135' => '1000', # tagoh

Modified: cdn/trunk/country/JPN_jp_cdn_araki_net.rb
===================================================================
--- cdn/trunk/country/JPN_jp_cdn_araki_net.rb	2010-02-06 14:48:21 UTC (rev 1000)
+++ cdn/trunk/country/JPN_jp_cdn_araki_net.rb	2010-02-11 06:12:04 UTC (rev 1001)
@@ -2,14 +2,14 @@
 $first_surrogate = '61.115.118.67'
 
 $surrogates = {
-  '203.178.137.175' => '9000', # naist
-  '150.65.7.130' => '9', # jaist
+#  '203.178.137.175' => '9000', # naist
+  '150.65.7.130' => '10', # jaist
   '61.115.118.67' => '1000', # hanzubon 2007apr5
-  '210.157.158.38' => '9900', # plat
+#  '210.157.158.38' => '9900', # plat
   '202.229.186.27' => '50', # topstudio
-  '133.5.166.3' => '10', # dennou-q.gfd-dennou.org
-  '130.54.59.159' => '10', # dennou-k.gfd-dennou.org
-  '133.87.45.30' => '10', # dennou-h.gfd-dennou.org
+  '133.5.166.3' => '20', # dennou-q.gfd-dennou.org
+  '130.54.59.159' => '20', # dennou-k.gfd-dennou.org
+  '133.87.45.30' => '40', # dennou-h.gfd-dennou.org
   '61.206.119.174' => '20', # oyu-net.jp
   '203.141.150.38' => '20', # mirrors.nemui.org
 ##  '219.111.15.135' => '1000', # tagoh

Modified: cdn/trunk/country_by_hand/JPN_deb_cdn_araki_net.rb
===================================================================
--- cdn/trunk/country_by_hand/JPN_deb_cdn_araki_net.rb	2010-02-06 14:48:21 UTC (rev 1000)
+++ cdn/trunk/country_by_hand/JPN_deb_cdn_araki_net.rb	2010-02-11 06:12:04 UTC (rev 1001)
@@ -3,13 +3,13 @@
 
 $surrogates = {
 #  '203.178.137.175' => '9000', # naist
-  '150.65.7.130' => '40', # jaist
+  '150.65.7.130' => '10', # jaist
   '61.115.118.67' => '1000', # hanzubon 2007apr5
 #  '210.157.158.38' => '9900', # plat
   '202.229.186.27' => '50', # topstudio
-  '133.5.166.3' => '10', # dennou-q.gfd-dennou.org
-  '130.54.59.159' => '10', # dennou-k.gfd-dennou.org
-  '133.87.45.30' => '10', # dennou-h.gfd-dennou.org
+  '133.5.166.3' => '20', # dennou-q.gfd-dennou.org
+  '130.54.59.159' => '20', # dennou-k.gfd-dennou.org
+  '133.87.45.30' => '40', # dennou-h.gfd-dennou.org
   '61.206.119.174' => '20', # oyu-net.jp
   '203.141.150.38' => '20', # mirrors.nemui.org
 ##  '219.111.15.135' => '1000', # tagoh

Modified: cdn/trunk/country_by_hand/JPN_jp_cdn_araki_net.rb
===================================================================
--- cdn/trunk/country_by_hand/JPN_jp_cdn_araki_net.rb	2010-02-06 14:48:21 UTC (rev 1000)
+++ cdn/trunk/country_by_hand/JPN_jp_cdn_araki_net.rb	2010-02-11 06:12:04 UTC (rev 1001)
@@ -3,13 +3,13 @@
 
 $surrogates = {
 #  '203.178.137.175' => '9000', # naist
-  '150.65.7.130' => '40', # jaist
+  '150.65.7.130' => '10', # jaist
   '61.115.118.67' => '1000', # hanzubon 2007apr5
 #  '210.157.158.38' => '9900', # plat
   '202.229.186.27' => '50', # topstudio
-  '133.5.166.3' => '10', # dennou-q.gfd-dennou.org
-  '130.54.59.159' => '10', # dennou-k.gfd-dennou.org
-  '133.87.45.30' => '10', # dennou-h.gfd-dennou.org
+  '133.5.166.3' => '20', # dennou-q.gfd-dennou.org
+  '130.54.59.159' => '20', # dennou-k.gfd-dennou.org
+  '133.87.45.30' => '40', # dennou-h.gfd-dennou.org
   '61.206.119.174' => '20', # oyu-net.jp
   '203.141.150.38' => '20', # mirrors.nemui.org
 ##  '219.111.15.135' => '1000', # tagoh

Modified: cdn/trunk/keepd/keepd.rb
===================================================================
--- cdn/trunk/keepd/keepd.rb	2010-02-06 14:48:21 UTC (rev 1000)
+++ cdn/trunk/keepd/keepd.rb	2010-02-11 06:12:04 UTC (rev 1001)
@@ -1,17 +1,62 @@
 #!/usr/bin/env ruby
 
-require 'drb/drb'
+require 'drb'
+require 'drb/ssl'
 require 'time'
+require 'optparse'
 
-$process_file = '/var/run/dns_balance_keepd.pid'
-$uri = "druby://localhost:38100"
+forceProcess = false
+configFile = ''
+pidFile = ''
+sslURI = ''
+dURI = ''
+verBose = false
 
+OptionParser.new do |opt|
+  opt.on("-f", "--force", "When some process is existed, kill and start"){|v| forceProcess = true}
+  opt.on("-v", "--verbose", "Verbose output"){|v| verBose = true}
+  opt.on("-c configFile", "--conf configFile", "Set config file. (default: $HOME/.cdn-keepd/cdn-keepd.conf)"){|v| configFile = v}
+  opt.on("-p PIDfile", "--pid-file PIDFile", "Set PID file. (default: /var/run/dns_balance_keepd.ped)"){|v| pidFile = v}
+  opt.on("-s sslURI", "--ssl-URI sslURI", "Set URI for drbssl (no default)"){|v| sslURI = v}
+  opt.on("-u URI", "Set URI for drb (default: druby://localhost:38100)"){|v| dURI = v}
+  opt.parse!(ARGV)
+end
+
+if configFile && configFile.size > 0
+  if File.exist? configFile
+    load configFile
+  else
+    puts "configFile is not existed."
+    exit 1
+  end
+elsif File.exist? File.expand_path(ENV['HOME'] + "/.cdn-keepd/cdn-keepd.conf")
+  load File.expand_path(ENV['HOME'] + "/.cdn-keepd/cdn-keepd.conf")
+else
+  puts "Please set ~/.cdn-keepd/cdn-keepd.conf"
+  $process_file = '/var/run/dns_balance_keepd.pid' unless $process_file
+  $uri = "druby://localhost:38100"
+end
+
+$process_file = pidFile if (pidFile && pidFile.size > 0)
+$sslURI = sslURI if (sslURI && sslURI.size > 0)
+$uri = dURI if (dURI && dURI.size > 0)
+
+
 class StoreSurrogates
   def initialize
     @ss = Hash.new
   end
 
-  def dstatus(host, code)
+  def dstatus(host, code, ctime=Time.now)
+    if host =~ /\A(?:25[0-5]|(?:2[0-4]|1\d|[1-9])?\d)(?:\.(?:25[0-5]|(?:2[0-4]|1\d|[1-9])?\d)){3}\z/
+    else
+      puts "no IPv4 address: #{host}"
+      return nil
+    end
+
+    if @ss[host] && @ss[host][1] && @ss[host][1] < ctime
+      @ss[host][1] = ctime
+    end
     if @ss[host] && @ss[host][2]
       failCount = @ss[host][2]
     else
@@ -22,20 +67,53 @@
     elsif code >= 200 && code < 300
       failCount = 0
     end
-    @ss[host] = [code.to_i, Time.now, failCount]
+    @ss[host] = [code.to_i, ctime, failCount]
   end
 
   def dcode(host)
     return @ss[host]
   end
+
+  def bulk_status(hostset)
+    puts "## bulk_status"
+    hostset.each do |k,v|
+      dstatus(k, v.to_i)
+    end
+  end
+
+  def bulk_get
+    return @ss
+  end
+
+  # dstatus(host, code, ctime=Time.now)
+  def bulk_put(statusset) # XXX
+    puts "## bulk_put"
+    statusset.each do |k,v|
+      begin
+        if v[1] > @ss[k][1]
+          puts "### put: " + k
+          @ss[k] = v
+        end 
+      rescue
+        p $!
+      end
+    end
+  end
+
 end
 
 
 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
+  if forceProcess
+    puts "kill old process"
+    Process.kill(15, old_pid)
+    sleep 1
+  else
+    exit 1
+    fail
+  end
 end
 
 fork{
@@ -55,11 +133,23 @@
     end
 
     STDIN.reopen("/dev/null", "r+")
-    STDOUT.reopen("/dev/null", "w")
-    STDERR.reopen("/dev/null", "w")
+    STDOUT.reopen("/dev/null", "w") unless verBose
+    STDERR.reopen("/dev/null", "w") unless verBose
 
-    DRb.start_service($uri,StoreSurrogates.new)
-    DRb.thread.join
+    ss = StoreSurrogates.new
+
+    if $uri
+      Thread.new do
+        DRb.start_service($uri,ss)
+        DRb.thread.join
+      end
+    end
+
+    if $sslUri && $drb_config
+      DRb.start_service $sslUri, ss, $drb_config
+      DRb.thread.join
+    end
+
     sleep
   }
 }

Modified: cdn/trunk/keepd/test-keepd.rb
===================================================================
--- cdn/trunk/keepd/test-keepd.rb	2010-02-06 14:48:21 UTC (rev 1000)
+++ cdn/trunk/keepd/test-keepd.rb	2010-02-11 06:12:04 UTC (rev 1001)
@@ -7,7 +7,7 @@
     @ss = Hash.new
   end
 
-  def dstatus(host, code)
+  def dstatus(host, code, ctime=Time.now)
     if @ss[host] && @ss[host][2]
       failCount = @ss[host][2]
     else
@@ -27,23 +27,27 @@
 
 end
 
-
+## normal drb test
 begin
   there = DRbObject.new_with_uri('druby://localhost:38100') 
+  puts "** druby test **"
   there.dstatus("127.0.0.2", 100)
 rescue 
-  there = StoreSurogateLocal.new
+  p $!
+  puts "** localtest **"
+  there = StoreSurrogateLocal.new
   there.dstatus("127.0.0.2", 100)
 end
 
-
 there.dstatus("127.0.0.2", 402)
 there.dstatus("127.0.0.4", 404)
 
 p there.dcode("127.0.0.2")
 there.dstatus("127.0.0.2", 402)
 p there.dcode("127.0.0.2")
+p there.dstatus("127.0.0.2", 402, Time.now - 5)
 
+
 there.dstatus("127.0.0.2", 200)
 p there.dcode("127.0.0.2")
 
@@ -51,17 +55,54 @@
 p there.dcode("195.178.192.118") #=>nil
 h4 = there.dcode("127.0.0.4")
 
+hoge = {
+  '10.100.0.1' => 201,
+  '10.100.0.2' => 202,
+  '300.100.0.2' => 404,
+  'no ip' => 404,
+}
+p hoge
+there.bulk_status(hoge)
+p there.dcode("10.100.0.1") #=>201
+p there.dcode("10.100.0.2") #=>202
+p there.dcode("300.100.0.2") #=>nil
+p there.dcode("no ip") #=>nil
 
+p bg1 = there.bulk_get
+there.bulk_put(bg1)
+
+
 if h4[1] + 1 < Time.now
   puts "must check"
 else
-  puts "no need to check"
+  puts "no need to check" # ok
 end
 
 sleep 1
 
 if h4[1] + 1 < Time.now
-  puts "must check"
+  puts "must check" # ok
 else
   puts "no need to check"
 end
+
+#drbssl test
+
+puts "** drbssl test **"
+
+require 'drb/ssl'
+there2 = "drbssl://localhost:38201"
+
+config = {
+  :SSLVerifyMode => OpenSSL::SSL::VERIFY_PEER,
+  :SSLCACertificateFile => "/Users/yaar/.cdn-keepd/CA/cacert.pem",
+  :SSLPrivateKey =>
+    OpenSSL::PKey::RSA.new(File.read("test/test_keypair.pem")),
+  :SSLCertificate =>
+    OpenSSL::X509::Certificate.new(File.read("test/cert_test.pem")),
+}
+
+DRb.start_service nil, nil, config
+h = DRbObject.new nil, there2
+
+p h.dcode("127.0.0.2")