New dep: robustserver. BDB::Env will reopen on error. Version 0.0.2
This commit is contained in:
parent
1989ade585
commit
34bb509b92
1
Rakefile
1
Rakefile
|
@ -13,6 +13,7 @@ begin
|
||||||
gem.files = ["README.md", "VERSION", "bin/**/*", "lib/**/*.rb", "test/**/*.rb"]
|
gem.files = ["README.md", "VERSION", "bin/**/*", "lib/**/*.rb", "test/**/*.rb"]
|
||||||
gem.require_paths = ["bin"]
|
gem.require_paths = ["bin"]
|
||||||
gem.add_dependency 'sbdb'
|
gem.add_dependency 'sbdb'
|
||||||
|
gem.add_dependency 'robustserver'
|
||||||
gem.add_dependency 'select'
|
gem.add_dependency 'select'
|
||||||
end
|
end
|
||||||
Jeweler::GemcutterTasks.new
|
Jeweler::GemcutterTasks.new
|
||||||
|
|
67
bin/s2l.rb
67
bin/s2l.rb
|
@ -5,8 +5,11 @@ require 'sbdb'
|
||||||
require 'uuidtools'
|
require 'uuidtools'
|
||||||
require 'socket'
|
require 'socket'
|
||||||
require 'select'
|
require 'select'
|
||||||
|
require 'robustserver'
|
||||||
|
|
||||||
class S2L < Select::Server
|
class S2L < Select::Server
|
||||||
|
attr_accessor :dbs
|
||||||
|
|
||||||
def init p
|
def init p
|
||||||
super p
|
super p
|
||||||
@dbs = p[:dbs]
|
@dbs = p[:dbs]
|
||||||
|
@ -105,58 +108,28 @@ class Rotate
|
||||||
alias emit put
|
alias emit put
|
||||||
end
|
end
|
||||||
|
|
||||||
class Retries
|
class Main < RobustServer
|
||||||
attr_accessor :max, :range
|
def initialize conf
|
||||||
attr_reader :count, :last
|
super
|
||||||
|
@conf = conf
|
||||||
def initialize max = 10, range = 10
|
info :open => S2L
|
||||||
@max, @range, @count, @last = max, range, 0, Time.now
|
@serv = S2L.new :sock => TCPServer.new( *@conf[:server])
|
||||||
|
info :create => {:home => @conf[:home]}
|
||||||
|
Dir.mkdir @conf[:home] rescue Errno::EEXIST
|
||||||
end
|
end
|
||||||
|
|
||||||
def retry?
|
def run
|
||||||
@count = @last + @range > Time.now ? @count + 1 : 1
|
info :open => SBDB::Env
|
||||||
@last = Time.now
|
SBDB::Env.new( @conf[:home], SBDB::CREATE | SBDB::Env::INIT_TRANSACTION | Bdb::DB_AUTO_COMMIT) do |dbenv|
|
||||||
@count < @max
|
info :open => Rotate
|
||||||
end
|
@serv.dbs = Rotate.new dbenv[ 'rotates.db', :type => SBDB::Btree, :flags => SBDB::CREATE | Bdb::DB_AUTO_COMMIT]
|
||||||
|
retries = Retries.new *@conf[:retries]
|
||||||
def run ex, &e
|
info :run => @serv
|
||||||
begin e.call *args
|
@serv.run
|
||||||
rescue ex
|
|
||||||
retries.retry? and retry
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
$conf = {
|
Main.main :home => 'logs', :server => [ '', 1514], :retries => [1,1] # [10, 10]
|
||||||
:home => 'logs',
|
|
||||||
:server => [ '', 1514],
|
|
||||||
:retries => [1,1] # [10, 10]
|
|
||||||
}
|
|
||||||
|
|
||||||
info :create => {:home => $conf[:home]}
|
|
||||||
Dir.mkdir $conf[:home] rescue Errno::EEXIST
|
|
||||||
|
|
||||||
info :open => SBDB::Env
|
|
||||||
SBDB::Env.new( $conf[:home], SBDB::CREATE | SBDB::Env::INIT_TRANSACTION | Bdb::DB_AUTO_COMMIT) do |dbenv|
|
|
||||||
info :open => Rotate
|
|
||||||
dbs = Rotate.new dbenv[ 'rotates.db', :type => SBDB::Btree, :flags => SBDB::CREATE | Bdb::DB_AUTO_COMMIT]
|
|
||||||
info :open => S2L
|
|
||||||
serv = S2L.new :sock => TCPServer.new( *$conf[:server]), :dbs => dbs
|
|
||||||
retries = Retries.new *$conf[:retries]
|
|
||||||
begin
|
|
||||||
info :run => serv
|
|
||||||
serv.run
|
|
||||||
info :shutdown => :stoped
|
|
||||||
rescue Interrupt
|
|
||||||
info :shutdown => :interrupted
|
|
||||||
rescue SignalException
|
|
||||||
info :shutdown => :signal
|
|
||||||
rescue Object
|
|
||||||
error :exception=>$!, :backtrace=>$!.backtrace
|
|
||||||
retries.retry? and retry
|
|
||||||
fatal "Too many retries (#{retries.count})"
|
|
||||||
info :shutdown => :fatal
|
|
||||||
end
|
|
||||||
info :close => dbenv
|
|
||||||
end
|
|
||||||
info :halted
|
info :halted
|
||||||
|
|
|
@ -5,11 +5,11 @@
|
||||||
|
|
||||||
Gem::Specification.new do |s|
|
Gem::Specification.new do |s|
|
||||||
s.name = %q{syslog2logan}
|
s.name = %q{syslog2logan}
|
||||||
s.version = "0.0.1"
|
s.version = "0.0.2"
|
||||||
|
|
||||||
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
||||||
s.authors = ["Denis Knauf"]
|
s.authors = ["Denis Knauf"]
|
||||||
s.date = %q{2010-02-07}
|
s.date = %q{2010-03-02}
|
||||||
s.default_executable = %q{s2l.rb}
|
s.default_executable = %q{s2l.rb}
|
||||||
s.description = %q{Syslog-Server which logs to Berkeley Databases (No SyslogDaemon)}
|
s.description = %q{Syslog-Server which logs to Berkeley Databases (No SyslogDaemon)}
|
||||||
s.email = %q{Denis.Knauf@gmail.com}
|
s.email = %q{Denis.Knauf@gmail.com}
|
||||||
|
@ -35,13 +35,16 @@ Gem::Specification.new do |s|
|
||||||
|
|
||||||
if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
|
if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
|
||||||
s.add_runtime_dependency(%q<sbdb>, [">= 0"])
|
s.add_runtime_dependency(%q<sbdb>, [">= 0"])
|
||||||
|
s.add_runtime_dependency(%q<robustserver>, [">= 0"])
|
||||||
s.add_runtime_dependency(%q<select>, [">= 0"])
|
s.add_runtime_dependency(%q<select>, [">= 0"])
|
||||||
else
|
else
|
||||||
s.add_dependency(%q<sbdb>, [">= 0"])
|
s.add_dependency(%q<sbdb>, [">= 0"])
|
||||||
|
s.add_dependency(%q<robustserver>, [">= 0"])
|
||||||
s.add_dependency(%q<select>, [">= 0"])
|
s.add_dependency(%q<select>, [">= 0"])
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
s.add_dependency(%q<sbdb>, [">= 0"])
|
s.add_dependency(%q<sbdb>, [">= 0"])
|
||||||
|
s.add_dependency(%q<robustserver>, [">= 0"])
|
||||||
s.add_dependency(%q<select>, [">= 0"])
|
s.add_dependency(%q<select>, [">= 0"])
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue