From a1d6f3691f4d219a2c0d9d572c1f9c4ba89b08ae Mon Sep 17 00:00:00 2001 From: Yuta Iwama Date: Wed, 30 Oct 2019 14:06:06 +0900 Subject: [PATCH] unify dry_run method and make @dry_run immutable Signed-off-by: Yuta Iwama --- lib/fluent/engine.rb | 6 ++--- lib/fluent/supervisor.rb | 54 ++++++++++++++++++---------------------- 2 files changed, 27 insertions(+), 33 deletions(-) diff --git a/lib/fluent/engine.rb b/lib/fluent/engine.rb index be106a9f33..6074a54592 100644 --- a/lib/fluent/engine.rb +++ b/lib/fluent/engine.rb @@ -47,12 +47,12 @@ def initialize MAINLOOP_SLEEP_INTERVAL = 0.3 - attr_reader :root_agent, :system_config, :supervisor_mode - attr_accessor :dry_run_mode + attr_reader :root_agent, :system_config, :supervisor_mode, :dry_run_mode - def init(system_config, supervisor_mode: false) + def init(system_config, supervisor_mode: false, dry_run_mode: false) @system_config = system_config @supervisor_mode = supervisor_mode + @dry_run_mode = dry_run_mode @suppress_config_dump = system_config.suppress_config_dump unless system_config.suppress_config_dump.nil? @without_source = system_config.without_source unless system_config.without_source.nil? diff --git a/lib/fluent/supervisor.rb b/lib/fluent/supervisor.rb index f118439da5..cf10e6baa4 100644 --- a/lib/fluent/supervisor.rb +++ b/lib/fluent/supervisor.rb @@ -492,7 +492,30 @@ def run_supervisor end end end - dry_run_cmd if @dry_run + + begin + if @dry_run + $log.info "starting fluentd-#{Fluent::VERSION} as dry run mode", ruby: RUBY_VERSION + end + + ServerEngine::Privilege.change(@chuser, @chgroup) + MessagePackFactory.init + Fluent::Engine.init(@system_config, supervisor: true, dry_run_mode: @dry_run) + Fluent::Engine.run_configure(@conf) + + if @dry_run + $log.info 'finsihed dry run mode' + exit 0 + end + rescue Fluent::ConfigError => e + $log.error 'config error', file: @config_path, error: e + $log.debug_backtrace + exit!(1) + rescue => e + $log.error(e) + exit(1) + end + supervise end @@ -588,32 +611,6 @@ def create_socket_manager ENV['SERVERENGINE_SOCKETMANAGER_PATH'] = socket_manager_path.to_s end - def dry_run_cmd - $log.info "starting fluentd-#{Fluent::VERSION} as dry run mode", ruby: RUBY_VERSION - dry_run - exit 0 - rescue => e - $log.error "dry run failed: #{e}" - exit 1 - end - - ## Set Engine's dry_run_mode true to override all target_id of worker sections - def dry_run - begin - Fluent::Engine.dry_run_mode = true - ServerEngine::Privilege.change(@chuser, @chgroup) - MessagePackFactory.init - Fluent::Engine.init(@system_config, supervisor: true) - Fluent::Engine.run_configure(@conf) - rescue Fluent::ConfigError => e - $log.error "config error", file: @config_path, error: e - $log.debug_backtrace - exit!(1) - ensure - Fluent::Engine.dry_run_mode = false - end - end - def show_plugin_config name, type = @show_plugin_config.split(":") # input:tail $log.info "show_plugin_config option is deprecated. Use fluent-plugin-config-format --format=txt #{name} #{type}" @@ -621,9 +618,6 @@ def show_plugin_config end def supervise - # Make dumpable conf, which is set corresponding_proxies for all elements in all worker sections - dry_run - Process.setproctitle("supervisor:#{@system_config.process_name}") if @system_config.process_name $log.info "starting fluentd-#{Fluent::VERSION}", pid: Process.pid, ruby: RUBY_VERSION