syslog2logan/bin/s2l.rb

59 lines
1.3 KiB
Ruby
Raw Normal View History

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'
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
class Main < RobustServer
def initialize conf
super
2011-03-19 09:59:06 +01:00
@logger = $logger
@conf = conf
2011-05-07 00:54:56 +02:00
logger.info :open => S2L
@serv = S2L.new :sock => TCPServer.new( *@conf[:server])
@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
end
def shutdown s = nil
2011-05-07 00:54:56 +02:00
logger.info :shutdown => [s, Signal[s]]
@serv.close
exit 0
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
@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]
2011-05-07 00:54:56 +02:00
logger.info :halted