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.require_paths = ["bin"]
|
||||
gem.add_dependency 'sbdb'
|
||||
gem.add_dependency 'robustserver'
|
||||
gem.add_dependency 'select'
|
||||
end
|
||||
Jeweler::GemcutterTasks.new
|
||||
|
|
75
bin/s2l.rb
75
bin/s2l.rb
|
@ -5,8 +5,11 @@ require 'sbdb'
|
|||
require 'uuidtools'
|
||||
require 'socket'
|
||||
require 'select'
|
||||
require 'robustserver'
|
||||
|
||||
class S2L < Select::Server
|
||||
attr_accessor :dbs
|
||||
|
||||
def init p
|
||||
super p
|
||||
@dbs = p[:dbs]
|
||||
|
@ -105,58 +108,28 @@ class Rotate
|
|||
alias emit put
|
||||
end
|
||||
|
||||
class Retries
|
||||
attr_accessor :max, :range
|
||||
attr_reader :count, :last
|
||||
|
||||
def initialize max = 10, range = 10
|
||||
@max, @range, @count, @last = max, range, 0, Time.now
|
||||
end
|
||||
|
||||
def retry?
|
||||
@count = @last + @range > Time.now ? @count + 1 : 1
|
||||
@last = Time.now
|
||||
@count < @max
|
||||
end
|
||||
|
||||
def run ex, &e
|
||||
begin e.call *args
|
||||
rescue ex
|
||||
retries.retry? and retry
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
$conf = {
|
||||
: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]
|
||||
class Main < RobustServer
|
||||
def initialize conf
|
||||
super
|
||||
@conf = conf
|
||||
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
|
||||
@serv = S2L.new :sock => TCPServer.new( *@conf[:server])
|
||||
info :create => {:home => @conf[:home]}
|
||||
Dir.mkdir @conf[:home] rescue Errno::EEXIST
|
||||
end
|
||||
info :close => dbenv
|
||||
|
||||
def run
|
||||
info :open => SBDB::Env
|
||||
SBDB::Env.new( @conf[:home], SBDB::CREATE | SBDB::Env::INIT_TRANSACTION | Bdb::DB_AUTO_COMMIT) do |dbenv|
|
||||
info :open => Rotate
|
||||
@serv.dbs = Rotate.new dbenv[ 'rotates.db', :type => SBDB::Btree, :flags => SBDB::CREATE | Bdb::DB_AUTO_COMMIT]
|
||||
retries = Retries.new *@conf[:retries]
|
||||
info :run => @serv
|
||||
@serv.run
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
Main.main :home => 'logs', :server => [ '', 1514], :retries => [1,1] # [10, 10]
|
||||
|
||||
info :halted
|
||||
|
|
|
@ -5,11 +5,11 @@
|
|||
|
||||
Gem::Specification.new do |s|
|
||||
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.authors = ["Denis Knauf"]
|
||||
s.date = %q{2010-02-07}
|
||||
s.date = %q{2010-03-02}
|
||||
s.default_executable = %q{s2l.rb}
|
||||
s.description = %q{Syslog-Server which logs to Berkeley Databases (No SyslogDaemon)}
|
||||
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
|
||||
s.add_runtime_dependency(%q<sbdb>, [">= 0"])
|
||||
s.add_runtime_dependency(%q<robustserver>, [">= 0"])
|
||||
s.add_runtime_dependency(%q<select>, [">= 0"])
|
||||
else
|
||||
s.add_dependency(%q<sbdb>, [">= 0"])
|
||||
s.add_dependency(%q<robustserver>, [">= 0"])
|
||||
s.add_dependency(%q<select>, [">= 0"])
|
||||
end
|
||||
else
|
||||
s.add_dependency(%q<sbdb>, [">= 0"])
|
||||
s.add_dependency(%q<robustserver>, [">= 0"])
|
||||
s.add_dependency(%q<select>, [">= 0"])
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue