Rotation and Listener (LogAn::Inc) importet

This commit is contained in:
Denis Knauf 2010-03-23 11:06:05 +01:00
parent fc04254b8e
commit 64a715a1b6
5 changed files with 312 additions and 67 deletions

View file

@ -2,21 +2,33 @@
require 'sbdb'
require 'safebox'
require 'robustserver'
_ = nil
Dir.mkdir 'logs' rescue Errno::EEXIST
SBDB::Env.new 'logs', SBDB::CREATE | SBDB::Env::INIT_TRANSACTION do |logs|
db = logs['test', :type => SBDB::Btree, :flags => SBDB::CREATE]
db = Safebox::Persistent.new db, db.cursor
$stdout.print "(0)$ "
STDIN.each_with_index do |line, i|
ret = Safebox.run line, Safebox::Box, db, _
if :value == ret.first
_ = ret.last
$stdout.puts "=> #{ret.last.inspect}"
else
$stdout.puts ret.last.inspect
end
$stdout.print "(#{i+1})$ "
class LogAn::Main < RobustServer
def initialize conf
super
@conf = conf
@logs = LogAn::Loglines.new 'logs'
Dir.mkdir 'etc' rescue Errno::EEXIST
@etc = SBDB::Env.new( 'etc',
log_config: SBDB::Env::LOG_IN_MEMORY | SBDB::Env::LOG_AUTO_REMOVE,
flags: SBDB::CREATE | SBDB::Env::INIT_TXN | Bdb::DB_INIT_MPOOL)
@serv = LogAn::Inc.new :sock => TCPServer.new( *@conf[:server])
@sigs[:INT] = @sigs[:TERM] = method(:shutdown)
end
def at_exit
@logs and @logs.close
@etc and @etc.close
end
def shutdown s = nil
$stderr.puts [:signal, s, Signal[s]].inspect
@serv.close
exit 0
end
def run
@serv.run
end
end