2010-03-01 01:28:13 +01:00
|
|
|
#!/usr/bin/ruby
|
|
|
|
|
|
|
|
require 'sbdb'
|
2010-03-20 23:33:14 +01:00
|
|
|
require 'safebox'
|
2010-03-23 11:06:05 +01:00
|
|
|
require 'robustserver'
|
2010-03-20 23:33:14 +01:00
|
|
|
|
2010-03-23 11:06:05 +01:00
|
|
|
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
|
2010-03-01 01:28:13 +01:00
|
|
|
end
|
|
|
|
end
|