[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Debian JP master SVN www commits (rev.909)
=======================================================
Repository: /org/svn.debian.or.jp/repos
Revision: 909
Commiter: yasu
Date: 2009-06-26 16:34:26 +0900 (金, 26 6月 2009)
=======================================================
Log:
add DRb status daemon
=======================================================
Changed:
U cdn/trunk/check-surrogates.rb
A cdn/trunk/example/dns_balance_keepd.sbin
U cdn/trunk/example/init
A cdn/trunk/keepd/
A cdn/trunk/keepd/keepd.rb
A cdn/trunk/keepd/test-keepd.rb
Modified: cdn/trunk/check-surrogates.rb
===================================================================
--- cdn/trunk/check-surrogates.rb 2009-06-24 13:00:05 UTC (rev 908)
+++ cdn/trunk/check-surrogates.rb 2009-06-26 07:34:26 UTC (rev 909)
@@ -8,7 +8,33 @@
require 'resolv'
require 'find'
require 'time'
+require 'drb/drb'
+class StoreSurrogateLocal
+ def initialize
+ @ss = Hash.new
+ end
+
+ def dstatus(host, code)
+ if @ss[host] && @ss[host][2]
+ failCount = @ss[host][2]
+ else
+ failCount = 0
+ end
+ if code >= 400
+ failCount += 1
+ elsif code >= 200 && code < 300
+ failCount = 0
+ end
+ @ss[host] = [code.to_i, Time.now, failCount]
+ end
+
+ def dcode(host)
+ return @ss[host]
+ end
+end
+
+
class CheckSurrogate
attr :lines
@@ -19,6 +45,16 @@
Syslog::Constants::LOG_CONS,
Syslog::Constants::LOG_DAEMON)
@last_modified = nil
+
+ begin
+ @keepd = DRbObject.new_with_uri('druby://localhost:38100')
+ @keepd.dstatus("127.0.0.2", 100)
+ rescue
+ @slog.info("Use StoreSurrogateLocal")
+ @keepd = StoreSurrogateLocal.new
+ @keepd.dstatus("127.0.0.2", 100)
+ end
+
end
def logclose
@@ -26,28 +62,40 @@
end
def checkhttp(host, tracefile, first_surrogate=nil, port=80)
- begin
+ begin
+ keep = @keepd.dcode(host)
+ if keep && keep[0] >= 500
+ return nil
+ elsif keep && keep[0] >= 400 && keep[1] + 10800 > Time.now
+ return nil
+ end
+
h = Net::HTTP.new(host, port)
h.open_timeout = 8
h.read_timeout = 8
- case response = h.head("/debian/project/trace/#{tracefile}", {"User-Agent" => "Debian-cdn-mirror-ping/1.0"})
+ case response = h.head("/debian/project/trace/#{tracefile}", {"User-Agent" => "Debian-cdn-mirror-ping/1.1"})
when Net::HTTPSuccess
if first_surrogate
@last_modified = Time.parse(response['last-modified'])
@slog.info("#{host} return #{response.code} #{@last_modified} set")
+ @keepd.dstatus(host, 200)
return true
elsif @last_modified && @last_modified == Time.parse(response['last-modified'])
@slog.info("#{host} return #{response.code} #{@last_modified} equal")
+ @keepd.dstatus(host, 200)
return true
elsif @last_modified && @last_modified != Time.parse(response['last-modified'])
@slog.info("#{host} return #{response.code} #{response['last-modified']} different timestamp. Ignore this host.")
+ @keepd.dstatus(host, 180)
return nil
else
@slog.info("#{host} return #{response.code} (please set $first_surrogate")
+ @keepd.dstatus(host, 200)
return true
end
else
@slog.info("#{host} return #{response.code}")
+ @keepd.dstatus(host, response.code)
return nil
end
rescue Timeout::Error
@@ -55,9 +103,11 @@
return nil
rescue Errno::ECONNREFUSED
@slog.info("#{host} refused open (#{$!})")
+ @keepd.dstatus(host, 500)
return nil
rescue
@slog.info("#{host} some error (#{$!})")
+ @keepd.dstatus(host, 500)
return nil
end
end
Added: cdn/trunk/example/dns_balance_keepd.sbin
===================================================================
--- cdn/trunk/example/dns_balance_keepd.sbin (rev 0)
+++ cdn/trunk/example/dns_balance_keepd.sbin 2009-06-26 07:34:26 UTC (rev 909)
@@ -0,0 +1,5 @@
+#!/bin/sh
+
+[ -f /home/yaar/Debian-JP/cdn/DNS-Balance/addr ] || exit 0
+
+cd /home/yaar/Debian-JP/cdn/DNS-Balance/keepd && ruby ./keepd.rb
Property changes on: cdn/trunk/example/dns_balance_keepd.sbin
___________________________________________________________________
Name: svn:executable
+ *
Modified: cdn/trunk/example/init
===================================================================
--- cdn/trunk/example/init 2009-06-24 13:00:05 UTC (rev 908)
+++ cdn/trunk/example/init 2009-06-26 07:34:26 UTC (rev 909)
@@ -24,10 +24,17 @@
DAEMON=/usr/sbin/$NAME
DAEMON_ARGS="--options args"
PIDFILE=/var/run/$NAME.pid
+
+NAME2=dns_balance_keepd
+DAEMON2=/usr/sbin/$NAME2
+DAEMON_ARGS2="--options args"
+PIDFILE2=/var/run/$NAME2.pid
+
SCRIPTNAME=/etc/init.d/$NAME
# Exit if the package is not installed
[ -x "$DAEMON" ] || exit 0
+[ -x "$DAEMON2" ] || exit 0
# Load the VERBOSE setting and other rcS variables
. /lib/init/vars.sh
@@ -46,9 +53,12 @@
# 1 if daemon was already running
# 2 if daemon could not be started
start-stop-daemon --start --quiet --pidfile $PIDFILE --exec $DAEMON --test > /dev/null \
+ && start-stop-daemon --start --quiet --pidfile $PIDFILE2 --exec $DAEMON2 --test > /dev/null \
|| return 1
start-stop-daemon --start --quiet --pidfile $PIDFILE --exec $DAEMON -- \
$DAEMON_ARGS \
+ && start-stop-daemon --start --quiet --pidfile $PIDFILE2 --exec $DAEMON2 -- \
+ $DAEMON_ARGS2 \
|| return 2
# Add code here, if necessary, that waits for the process to be ready
# to handle requests from services started subsequently which depend
@@ -65,7 +75,8 @@
# 1 if daemon was already stopped
# 2 if daemon could not be stopped
# other if a failure occurred
- start-stop-daemon --stop --quiet --pidfile $PIDFILE
+ start-stop-daemon --stop --quiet --pidfile $PIDFILE \
+ && start-stop-daemon --stop --quiet --pidfile $PIDFILE2
RETVAL="$?"
[ "$RETVAL" = 2 ] && return 2
# Wait for children to finish too if this is a daemon that forks
@@ -74,10 +85,12 @@
# that waits for the process to drop all resources that could be
# needed by services started subsequently. A last resort is to
# sleep for some time.
- start-stop-daemon --stop --quiet --oknodo --retry=0/30/KILL/5 --exec $DAEMON
+ start-stop-daemon --stop --quiet --oknodo --retry=0/30/KILL/5 --exec $DAEMON \
+ && start-stop-daemon --stop --quiet --oknodo --retry=0/30/KILL/5 --exec $DAEMON2
[ "$?" = 2 ] && return 2
# Many daemons don't delete their pidfiles when they exit.
rm -f $PIDFILE
+ rm -f $PIDFILE2
return "$RETVAL"
}
@@ -91,6 +104,7 @@
# then implement that here.
#
start-stop-daemon --stop --signal 1 --quiet --pidfile $PIDFILE --name $NAME
+ start-stop-daemon --stop --signal 1 --quiet --pidfile $PIDFILE2 --name $NAME2
return 0
}
Added: cdn/trunk/keepd/keepd.rb
===================================================================
--- cdn/trunk/keepd/keepd.rb (rev 0)
+++ cdn/trunk/keepd/keepd.rb 2009-06-26 07:34:26 UTC (rev 909)
@@ -0,0 +1,65 @@
+#!/usr/bin/env ruby
+
+require 'drb/drb'
+require 'time'
+
+$process_file = '/var/run/dns_balance_keepd.pid'
+$uri = "druby://localhost:38100"
+
+class StoreSurrogates
+ def initialize
+ @ss = Hash.new
+ end
+
+ def dstatus(host, code)
+ if @ss[host] && @ss[host][2]
+ failCount = @ss[host][2]
+ else
+ failCount = 0
+ end
+ if code >= 400
+ failCount += 1
+ elsif code >= 200 && code < 300
+ failCount = 0
+ end
+ @ss[host] = [code.to_i, Time.now, failCount]
+ end
+
+ def dcode(host)
+ return @ss[host]
+ 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
+end
+
+fork{
+ Process::setsid
+ fork{
+ pid = Process.pid
+ print "Start #{$0} running pid is #{pid}\n"
+ pidfile = open($process_file, "w+")
+ pidfile.write(pid)
+ pidfile.flush
+
+ begin
+ Process::UID.eid=65534
+ rescue
+ puts $!
+ puts "run by uid #{Process.euid}"
+ end
+
+ STDIN.reopen("/dev/null", "r+")
+ STDOUT.reopen("/dev/null", "w")
+ STDERR.reopen("/dev/null", "w")
+
+ DRb.start_service($uri,StoreSurrogates.new)
+ DRb.thread.join
+ sleep
+ }
+}
Added: cdn/trunk/keepd/test-keepd.rb
===================================================================
--- cdn/trunk/keepd/test-keepd.rb (rev 0)
+++ cdn/trunk/keepd/test-keepd.rb 2009-06-26 07:34:26 UTC (rev 909)
@@ -0,0 +1,67 @@
+#!/usr/bin/env ruby
+
+require 'drb/drb'
+
+class StoreSurrogateLocal
+ def initialize
+ @ss = Hash.new
+ end
+
+ def dstatus(host, code)
+ if @ss[host] && @ss[host][2]
+ failCount = @ss[host][2]
+ else
+ failCount = 0
+ end
+ if code >= 400
+ failCount += 1
+ elsif code >= 200 && code < 300
+ failCount = 0
+ end
+ @ss[host] = [code.to_i, Time.now, failCount]
+ end
+
+ def dcode(host)
+ return @ss[host]
+ end
+
+end
+
+
+begin
+ there = DRbObject.new_with_uri('druby://localhost:38100')
+ there.dstatus("127.0.0.2", 100)
+rescue
+ there = StoreSurogateLocal.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")
+
+there.dstatus("127.0.0.2", 200)
+p there.dcode("127.0.0.2")
+
+p there.dcode("202.158.214.106") #=>nil
+p there.dcode("195.178.192.118") #=>nil
+h4 = there.dcode("127.0.0.4")
+
+
+if h4[1] + 1 < Time.now
+ puts "must check"
+else
+ puts "no need to check"
+end
+
+sleep 1
+
+if h4[1] + 1 < Time.now
+ puts "must check"
+else
+ puts "no need to check"
+end