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

Debian JP master SVN www commits (rev.275)



=======================================================
Repository: /org/svn.debian.or.jp/repos
  Revision: 275
  Commiter: yasu
      Date: 2007-04-28 18:26:12 +0900 (土, 28  4月 2007)
=======================================================
Log:

New feature: it can resolve multiple hostnames.

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

U   cdn/ChangeLog
U   cdn/README
U   cdn/README.eng
U   cdn/check-surrogates.rb
D   cdn/config-server-lists.rb
A   cdn/lists_deb_cdn_araki_net.rb
A   cdn/lists_jp_cdn_araki_net.rb

Modified: cdn/ChangeLog
===================================================================
--- cdn/ChangeLog	2007-04-28 01:20:42 UTC (rev 274)
+++ cdn/ChangeLog	2007-04-28 09:26:12 UTC (rev 275)
@@ -1,5 +1,14 @@
-2007-04-23  ARAKI Yasuhiro  <ar@xxxxxxxxxxxxx>
+2007-04-28  ARAKI Yasuhiro  <yasu@debian.or.jp>
 
+	** New feature: it can resolve multiple hostnames.
+	* README: 
+	* README.eng:
+	* lists_deb_cdn_araki_net.rb: New file.
+	* lists_jp_cdn_araki_net.rb: New file.
+	* check-surrogates.rb (CheckSurrogate): Add this class to resolve multiple hostnames.
+
+2007-04-23  ARAKI Yasuhiro  <yasu@debian.or.jp>
+
 	* check-surrogates.rb (checkhttp): Added syslog record for Errno::ECONNREFUSED.
 
 2007-04-17  ARAKI Yasuhiro  <yasu@debian.or.jp>

Modified: cdn/README
===================================================================
--- cdn/README	2007-04-28 01:20:42 UTC (rev 274)
+++ cdn/README	2007-04-28 09:26:12 UTC (rev 275)
@@ -1,17 +1,33 @@
 使いかた
 
-https://osdn.debian.or.jp/repos/cdn からダウンロードする。
+0. Rubyをまずインストールします。また、DNSを使用するためbind等他DNSが動作しているホストでは使えません。
 
-check-surrogates.rb をcronでまわすようにする。
+1. https://osdn.debian.or.jp/repos/cdn からダウンロードする。
 
+2. 名前を返す候補リストファイルを作る。
+ファイル名は lists_hostname.rb (hostnameの . を _ に変更する)
+例えばjp.cdn.araki.netならば、lists_jp_cdn_araki_net.rbになる。
+
+3. check-surrogates.rb をcronでまわすようにする。
+(例)
+
  */2 * * * * cd /home/yasu2/Debian-JP/DNS-Balance-2.0 && ruby check-surrogates.rb
 
 これが動くと addr というファイルが作られる。
 
-DNS-Balance/addr -> addr のリンクをつくる。
+4. DNS-Balance/addr -> addr のリンクをつくる。
 
-DNS-Balanceを動作させる。(これはrootで動いている必要がある)
+5. DNS-Balanceを動作させる。(これはrootで動いている必要がある)
+
+ # ruby dns_balance.rb 
+
+動作するIPアドレスを指定するならば。-i をつける。
+
  # ruby dns_balance.rb -i 210.157.158.38
 
-/var/log/syslog/daemon.log などを確認する。
+6. /var/log/syslog/daemon.log などを確認する。
 
+ Apr 28 18:06:00 localhost check-surrogates.rb[12288]: 61.115.118.67 return 200
+
+などのような出力が出ていれば問題ない。
+

Modified: cdn/README.eng
===================================================================
--- cdn/README.eng	2007-04-28 01:20:42 UTC (rev 274)
+++ cdn/README.eng	2007-04-28 09:26:12 UTC (rev 275)
@@ -3,16 +3,19 @@
 
 1. Checkout https://osdn.debian.or.jp/repos/cdn by using Subversion
 
-2. Set crontab for check-surrogates.rb (by normal user account)
+2. Write surrogates list file to resolv. This filename is lists_host_your_domain.rb. 
+(cf. Filename for 'jp.cdn.araki.net' is 'lists_jp_cdn_araki_net.rb').
 
+3. Set crontab for check-surrogates.rb (by normal user account)
+
  */2 * * * * cd /home/yasu2/Debian-JP/DNS-Balance-2.0 && ruby check-surrogates.rb
 
   This program will create a file "addr".
 
-3. Make a symlink DNS-Balance/addr -> addr
+4. Make a symlink DNS-Balance/addr -> addr
 
-4. Run DNS-Balance. (by root account)
+5. Run DNS-Balance. (by root account)
  # ruby dns_balance.rb -i 210.157.158.38
   (-i specifies the address to listen. If you have only a single IP, you don't have to use this option)
 
-5. Check /var/log/syslog and /var/log/daemon.log.
+6. Check /var/log/syslog and /var/log/daemon.log.

Modified: cdn/check-surrogates.rb
===================================================================
--- cdn/check-surrogates.rb	2007-04-28 01:20:42 UTC (rev 274)
+++ cdn/check-surrogates.rb	2007-04-28 09:26:12 UTC (rev 275)
@@ -6,51 +6,85 @@
 require 'net/http'
 require 'uri'
 require 'resolv'
+require 'find'
 
-sslog = Syslog.open(__FILE__,   
-                  Syslog::Constants::LOG_PID |
-                  Syslog::Constants::LOG_CONS,
-                  Syslog::Constants::LOG_DAEMON)
+class CheckSurrogate
+  attr :lines
 
-require File.dirname(__FILE__) + '/config-server-lists'
-surrogates = $surrogates
+  def initialize
+    @lines = ''
+    @slog = Syslog.open(__FILE__,   
+                        Syslog::Constants::LOG_PID |
+                        Syslog::Constants::LOG_CONS,
+                        Syslog::Constants::LOG_DAEMON)
+  end
 
-def checkhttp(host, slog, codename='sid', port=80, tl=5)
-  begin 
-    h = Net::HTTP.new(host, port)
-    h.open_timeout = 8 
-    h.read_timeout = 8
-    case response = h.head("/debian/dists/#{codename}/Release", nil)
-    when Net::HTTPSuccess
-      slog.info("#{host} return #{response.code}")
-      return true
-    else
-      slog.info("#{host} return #{response.code}")
+  def checkhttp(host, codename='sid', port=80, tl=5)
+    begin 
+      h = Net::HTTP.new(host, port)
+      h.open_timeout = 8 
+      h.read_timeout = 8
+      case response = h.head("/debian/dists/#{codename}/Release", nil)
+      when Net::HTTPSuccess
+        @slog.info("#{host} return #{response.code}")
+        return true
+      else
+        @slog.info("#{host} return #{response.code}")
+        return nil
+      end
+    rescue Timeout::Error
+      @slog.info("#{host} timeout (#{$!})")
       return nil
+    rescue Errno::ECONNREFUSED
+      @slog.info("#{host} refused open (#{$!})")
+      return nil
+    rescue
+      @slog.info("#{host} some error (#{$!})")
+      return nil
     end
-  rescue Timeout::Error
-    slog.info("#{host} timeout (#{$!})")
-    return nil
-  rescue Errno::ECONNREFUSED
-    slog.info("#{host} refused open (#{$!})")
-    return nil
-  rescue
-    slog.info("#{host} some error (#{$!})")
-    return nil
   end
-end
 
-s_active = Hash.new
+  def make_surrogate_line(listfile)
+    domain = listfile.gsub(/\.\/lists_/, '')
+    domain.gsub!(/_/, '.')
 
-surrogates.each do |t_ip, t_value|
-  if checkhttp(t_ip, sslog)
-    s_active[t_ip.gsub('.',',')] = t_value
-  else
+    surrogates = ''
+    require listfile
+    surrogates = $surrogates
+
+    s_active = Hash.new
+    surrogates.each do |t_ip, t_value|
+      if checkhttp(t_ip)
+        s_active[t_ip.gsub('.',',')] = t_value
+      else
+      end
+    end
+
+    @lines += "\t\"#{domain}\" => [\n"
+    s_active.each do |k,v|
+      @lines += "\t\t" + '[[' + k + '], ' + v + '],' + "\n"
+    end
+    @lines += "\t],\n"
+
   end
 end
 
+domains = Array.new
+listfiles = Array.new
+Find.find(File.dirname(__FILE__)) do |f|
+  if f =~ /^\.\/lists_([\w_]+)\.rb$/
+    cl = $1
+    listfiles.push f.gsub(/\.rb$/,'')
+  end
+end
+
+cs = CheckSurrogate.new
+
+listfiles.each do |f|
+  cs.make_surrogate_line(f)
+end
+
 foo = File.open("addr", 'w')
-
 foo.puts "##" + Time.now.to_s + "\n\n"
 foo.puts '$addr_db = {
   "default" => {
@@ -60,17 +94,11 @@
     "localhost" => [
       [[127,0,0,1], 0],
     ],
-    "deb.cdn.araki.net" => [
 '
-s_active.each do |k,v|
-  foo.puts "\t" + '[[' + k + '], ' + v + '],' + "\n"
-end
+foo.puts cs.lines
 
 foo.puts '
-    ],
   },
 }'
 
 foo.close
-sslog.close
-

Deleted: cdn/config-server-lists.rb
===================================================================
--- cdn/config-server-lists.rb	2007-04-28 01:20:42 UTC (rev 274)
+++ cdn/config-server-lists.rb	2007-04-28 09:26:12 UTC (rev 275)
@@ -1,11 +0,0 @@
-$surrogates = {
-  '203.178.137.175' => '9000', # naist
-  '61.115.118.67' => '20', # hanzubon 2007apr5
-  '210.157.158.38' => '9900', # plat
-  '202.229.186.27' => '20', # topstudio
-  '133.5.166.3' => '10', # dennou-q.gfd-dennou.org
-  '130.54.59.159' => '10', # dennou-k.gfd-dennou.org
-  '133.50.218.117' => '10', # dennou-h.gfd-dennou.org
-#  '15.12.218.222' => '9900', # fail data for test
-#  '210.157.158.59' => '9900' ## fail data for test
-}

Copied: cdn/lists_deb_cdn_araki_net.rb (from rev 274, cdn/config-server-lists.rb)
===================================================================
--- cdn/lists_deb_cdn_araki_net.rb	                        (rev 0)
+++ cdn/lists_deb_cdn_araki_net.rb	2007-04-28 09:26:12 UTC (rev 275)
@@ -0,0 +1,11 @@
+$surrogates = {
+  '203.178.137.175' => '9000', # naist
+  '61.115.118.67' => '20', # hanzubon 2007apr5
+  '210.157.158.38' => '9900', # plat
+  '202.229.186.27' => '20', # topstudio
+  '133.5.166.3' => '10', # dennou-q.gfd-dennou.org
+  '130.54.59.159' => '10', # dennou-k.gfd-dennou.org
+  '133.50.218.117' => '10', # dennou-h.gfd-dennou.org
+#  '15.12.218.222' => '9900', # fail data for test
+#  '210.157.158.59' => '9900' ## fail data for test
+}

Added: cdn/lists_jp_cdn_araki_net.rb
===================================================================
--- cdn/lists_jp_cdn_araki_net.rb	                        (rev 0)
+++ cdn/lists_jp_cdn_araki_net.rb	2007-04-28 09:26:12 UTC (rev 275)
@@ -0,0 +1,11 @@
+$surrogates = {
+  '203.178.137.175' => '9000', # naist
+  '61.115.118.67' => '20', # hanzubon 2007apr5
+  '210.157.158.38' => '9900', # plat
+  '202.229.186.27' => '20', # topstudio
+  '133.5.166.3' => '10', # dennou-q.gfd-dennou.org
+  '130.54.59.159' => '10', # dennou-k.gfd-dennou.org
+  '133.50.218.117' => '10', # dennou-h.gfd-dennou.org
+#  '15.12.218.222' => '9900', # fail data for test
+#  '210.157.158.59' => '9900' ## fail data for test
+}