2010-01-30 14:58:28 +01:00
|
|
|
#!/usr/bin/ruby
|
|
|
|
|
2011-06-08 22:51:40 +02:00
|
|
|
$:.push File.join( File.dirname( $0), '..', 'lib')
|
2011-03-19 09:59:06 +01:00
|
|
|
require 'logger'
|
2011-06-08 22:51:40 +02:00
|
|
|
require 'json'
|
2010-01-30 14:58:28 +01:00
|
|
|
require 'rubygems'
|
|
|
|
require 'uuidtools'
|
|
|
|
require 'socket'
|
|
|
|
require 'select'
|
2010-03-02 14:10:58 +01:00
|
|
|
require 'robustserver'
|
2011-05-07 00:54:56 +02:00
|
|
|
require 'active_support'
|
|
|
|
require 'syslog2logan/rotate'
|
2011-06-08 22:51:40 +02:00
|
|
|
require 'syslog2logan/server'
|
2010-01-30 14:58:28 +01:00
|
|
|
|
2011-03-19 09:59:06 +01:00
|
|
|
$logger = Logger.new $stderr
|
2011-06-08 22:51:40 +02:00
|
|
|
$logger.formatter = proc { |severity, datetime, progname, msg| [severity, datetime, progname, msg.inspect].to_json+"\n" }
|
2010-01-30 14:58:28 +01:00
|
|
|
|
|
|
|
module Kernel
|
2011-05-07 00:54:56 +02:00
|
|
|
def logger() $logger end
|
2010-01-30 14:58:28 +01:00
|
|
|
end
|
|
|
|
|
2010-03-02 14:10:58 +01:00
|
|
|
class Main < RobustServer
|
|
|
|
def initialize conf
|
|
|
|
super
|
2011-03-19 09:59:06 +01:00
|
|
|
@logger = $logger
|
2010-03-02 14:10:58 +01:00
|
|
|
@conf = conf
|
2011-05-07 00:54:56 +02:00
|
|
|
logger.info :open => S2L
|
2010-03-02 14:10:58 +01:00
|
|
|
@serv = S2L.new :sock => TCPServer.new( *@conf[:server])
|
2010-03-11 00:34:01 +01:00
|
|
|
@sigs[:INT] = @sigs[:TERM] = method(:shutdown)
|
2011-03-19 09:59:06 +01:00
|
|
|
@sigs[:USR1] = method(:state)
|
|
|
|
end
|
|
|
|
|
|
|
|
def state s = nil
|
2011-06-08 22:51:40 +02:00
|
|
|
logger.debug :server => @serv.class
|
2010-03-11 00:34:01 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
def shutdown s = nil
|
2011-05-07 00:54:56 +02:00
|
|
|
logger.info :shutdown => [s, Signal[s]]
|
2010-03-11 00:34:01 +01:00
|
|
|
@serv.close
|
|
|
|
exit 0
|
2010-03-02 14:10:58 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
def run
|
2011-06-08 22:51:40 +02:00
|
|
|
logger.info :open => @conf[:backend]
|
|
|
|
@conf[:backend][0].new( @conf[:backend][1]) do |backend|
|
2011-05-07 00:54:56 +02:00
|
|
|
logger.info :open => Rotate
|
2011-06-08 22:51:40 +02:00
|
|
|
@serv.dbs = Rotate.new &backend.to_proc
|
|
|
|
logger.info :run => @serv.class
|
2010-03-02 14:10:58 +01:00
|
|
|
@serv.run
|
2011-06-08 22:51:40 +02:00
|
|
|
logger.info :close => @conf[:backend]
|
2010-01-30 14:58:28 +01:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2011-06-08 22:51:40 +02:00
|
|
|
require 'syslog2logan/backend/tch'
|
|
|
|
Main.main :backend => [ Backend::TCH, {:dir => 'logs'}], :server => [ '', 1514], :retries => [1,1] # [10, 10]
|
2010-03-02 14:10:58 +01:00
|
|
|
|
2011-05-07 00:54:56 +02:00
|
|
|
logger.info :halted
|