lib/fluent/engine.rb in fluentd-0.10.6 vs lib/fluent/engine.rb in fluentd-0.10.7
- old
+ new
@@ -21,10 +21,12 @@
class EngineClass
def initialize
@matches = []
@sources = []
@match_cache = {}
+ @started = []
+ @default_loop = nil
end
def init
BasicSocket.do_not_reverse_lookup = true
Plugin.load_plugins
@@ -127,45 +129,59 @@
# TODO thread update
Time.now.to_i
end
def run
- start
+ begin
+ start
- if match?($log.tag)
- $log.enable_event
- end
+ if match?($log.tag)
+ $log.enable_event
+ end
- # for empty loop
- Coolio::Loop.default.attach Coolio::TimerWatcher.new(1, true)
- # TODO attach async watch for thread pool
- Coolio::Loop.default.run
+ # for empty loop
+ @default_loop = Coolio::Loop.default
+ @default_loop.attach Coolio::TimerWatcher.new(1, true)
+ # TODO attach async watch for thread pool
+ @default_loop.run
- shutdown
+ rescue
+ $log.error "unexpected error", :error=>$!.to_s
+ $log.error_backtrace
+ ensure
+ shutdown
+ end
end
def stop
$log.info "shutting down fluentd"
- Coolio::Loop.default.stop
+ if @default_loop
+ @default_loop.stop
+ @default_loop = nil
+ end
nil
end
private
def start
@matches.each {|m|
m.start
+ @started << m
}
@sources.each {|s|
s.start
+ @started << s
}
end
def shutdown
- @matches.each {|m|
- m.shutdown rescue nil
- }
- @sources.each {|s|
- s.shutdown rescue nil
+ @started.reverse_each {|s|
+ begin
+ s.shutdown
+ rescue
+ $log.warn "unexpected error while shutting down", :error=>$!.to_s
+ $log.warn_backtrace
+ end
}
end
def flush_recursive(array)
array.each {|m|