fluentd222 1.16.2-x86_64-linux
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
 - data/.deepsource.toml +13 -0
 - data/.github/ISSUE_TEMPLATE/bug_report.yaml +71 -0
 - data/.github/ISSUE_TEMPLATE/config.yml +5 -0
 - data/.github/ISSUE_TEMPLATE/feature_request.yaml +39 -0
 - data/.github/ISSUE_TEMPLATE.md +17 -0
 - data/.github/PULL_REQUEST_TEMPLATE.md +14 -0
 - data/.github/workflows/stale-actions.yml +24 -0
 - data/.github/workflows/test-ruby-head.yaml +31 -0
 - data/.github/workflows/test.yaml +32 -0
 - data/.gitignore +30 -0
 - data/ADOPTERS.md +5 -0
 - data/AUTHORS +2 -0
 - data/CHANGELOG.md +2720 -0
 - data/CONTRIBUTING.md +45 -0
 - data/GOVERNANCE.md +55 -0
 - data/Gemfile +9 -0
 - data/GithubWorkflow.md +78 -0
 - data/LICENSE +202 -0
 - data/MAINTAINERS.md +13 -0
 - data/README.md +75 -0
 - data/Rakefile +79 -0
 - data/SECURITY.md +14 -0
 - data/bin/fluent-binlog-reader +7 -0
 - data/bin/fluent-ca-generate +6 -0
 - data/bin/fluent-cap-ctl +7 -0
 - data/bin/fluent-cat +5 -0
 - data/bin/fluent-ctl +7 -0
 - data/bin/fluent-debug +5 -0
 - data/bin/fluent-gem +9 -0
 - data/bin/fluent-plugin-config-format +5 -0
 - data/bin/fluent-plugin-generate +5 -0
 - data/bin/fluentd +15 -0
 - data/code-of-conduct.md +3 -0
 - data/docs/SECURITY_AUDIT.pdf +0 -0
 - data/example/copy_roundrobin.conf +39 -0
 - data/example/counter.conf +18 -0
 - data/example/filter_stdout.conf +22 -0
 - data/example/in_forward.conf +14 -0
 - data/example/in_forward_client.conf +37 -0
 - data/example/in_forward_shared_key.conf +15 -0
 - data/example/in_forward_tls.conf +14 -0
 - data/example/in_forward_users.conf +24 -0
 - data/example/in_forward_workers.conf +21 -0
 - data/example/in_http.conf +16 -0
 - data/example/in_out_forward.conf +17 -0
 - data/example/in_sample_blocks.conf +17 -0
 - data/example/in_sample_with_compression.conf +23 -0
 - data/example/in_syslog.conf +15 -0
 - data/example/in_tail.conf +14 -0
 - data/example/in_tcp.conf +13 -0
 - data/example/in_udp.conf +13 -0
 - data/example/logevents.conf +25 -0
 - data/example/multi_filters.conf +61 -0
 - data/example/out_copy.conf +20 -0
 - data/example/out_exec_filter.conf +42 -0
 - data/example/out_file.conf +13 -0
 - data/example/out_forward.conf +35 -0
 - data/example/out_forward_buf_file.conf +23 -0
 - data/example/out_forward_client.conf +109 -0
 - data/example/out_forward_heartbeat_none.conf +16 -0
 - data/example/out_forward_sd.conf +17 -0
 - data/example/out_forward_shared_key.conf +36 -0
 - data/example/out_forward_tls.conf +18 -0
 - data/example/out_forward_users.conf +65 -0
 - data/example/out_null.conf +36 -0
 - data/example/sd.yaml +8 -0
 - data/example/secondary_file.conf +42 -0
 - data/example/suppress_config_dump.conf +7 -0
 - data/example/v0_12_filter.conf +78 -0
 - data/example/v1_literal_example.conf +36 -0
 - data/example/worker_section.conf +36 -0
 - data/fluent.conf +139 -0
 - data/fluentd.gemspec +54 -0
 - data/lib/fluent/agent.rb +168 -0
 - data/lib/fluent/capability.rb +87 -0
 - data/lib/fluent/clock.rb +66 -0
 - data/lib/fluent/command/binlog_reader.rb +244 -0
 - data/lib/fluent/command/bundler_injection.rb +45 -0
 - data/lib/fluent/command/ca_generate.rb +184 -0
 - data/lib/fluent/command/cap_ctl.rb +174 -0
 - data/lib/fluent/command/cat.rb +365 -0
 - data/lib/fluent/command/ctl.rb +180 -0
 - data/lib/fluent/command/debug.rb +103 -0
 - data/lib/fluent/command/fluentd.rb +374 -0
 - data/lib/fluent/command/plugin_config_formatter.rb +308 -0
 - data/lib/fluent/command/plugin_generator.rb +365 -0
 - data/lib/fluent/compat/call_super_mixin.rb +76 -0
 - data/lib/fluent/compat/detach_process_mixin.rb +33 -0
 - data/lib/fluent/compat/exec_util.rb +129 -0
 - data/lib/fluent/compat/file_util.rb +54 -0
 - data/lib/fluent/compat/filter.rb +68 -0
 - data/lib/fluent/compat/formatter.rb +111 -0
 - data/lib/fluent/compat/formatter_utils.rb +85 -0
 - data/lib/fluent/compat/handle_tag_and_time_mixin.rb +62 -0
 - data/lib/fluent/compat/handle_tag_name_mixin.rb +53 -0
 - data/lib/fluent/compat/input.rb +49 -0
 - data/lib/fluent/compat/output.rb +721 -0
 - data/lib/fluent/compat/output_chain.rb +60 -0
 - data/lib/fluent/compat/parser.rb +310 -0
 - data/lib/fluent/compat/parser_utils.rb +40 -0
 - data/lib/fluent/compat/propagate_default.rb +62 -0
 - data/lib/fluent/compat/record_filter_mixin.rb +34 -0
 - data/lib/fluent/compat/set_tag_key_mixin.rb +50 -0
 - data/lib/fluent/compat/set_time_key_mixin.rb +69 -0
 - data/lib/fluent/compat/socket_util.rb +165 -0
 - data/lib/fluent/compat/string_util.rb +34 -0
 - data/lib/fluent/compat/structured_format_mixin.rb +26 -0
 - data/lib/fluent/compat/type_converter.rb +90 -0
 - data/lib/fluent/config/basic_parser.rb +123 -0
 - data/lib/fluent/config/configure_proxy.rb +424 -0
 - data/lib/fluent/config/dsl.rb +152 -0
 - data/lib/fluent/config/element.rb +265 -0
 - data/lib/fluent/config/error.rb +44 -0
 - data/lib/fluent/config/literal_parser.rb +286 -0
 - data/lib/fluent/config/parser.rb +107 -0
 - data/lib/fluent/config/section.rb +272 -0
 - data/lib/fluent/config/types.rb +249 -0
 - data/lib/fluent/config/v1_parser.rb +192 -0
 - data/lib/fluent/config/yaml_parser/fluent_value.rb +47 -0
 - data/lib/fluent/config/yaml_parser/loader.rb +108 -0
 - data/lib/fluent/config/yaml_parser/parser.rb +166 -0
 - data/lib/fluent/config/yaml_parser/section_builder.rb +107 -0
 - data/lib/fluent/config/yaml_parser.rb +56 -0
 - data/lib/fluent/config.rb +89 -0
 - data/lib/fluent/configurable.rb +201 -0
 - data/lib/fluent/counter/base_socket.rb +44 -0
 - data/lib/fluent/counter/client.rb +297 -0
 - data/lib/fluent/counter/error.rb +86 -0
 - data/lib/fluent/counter/mutex_hash.rb +163 -0
 - data/lib/fluent/counter/server.rb +273 -0
 - data/lib/fluent/counter/store.rb +205 -0
 - data/lib/fluent/counter/validator.rb +145 -0
 - data/lib/fluent/counter.rb +23 -0
 - data/lib/fluent/daemon.rb +13 -0
 - data/lib/fluent/daemonizer.rb +88 -0
 - data/lib/fluent/engine.rb +253 -0
 - data/lib/fluent/env.rb +40 -0
 - data/lib/fluent/error.rb +37 -0
 - data/lib/fluent/event.rb +330 -0
 - data/lib/fluent/event_router.rb +315 -0
 - data/lib/fluent/ext_monitor_require.rb +28 -0
 - data/lib/fluent/file_wrapper.rb +137 -0
 - data/lib/fluent/filter.rb +21 -0
 - data/lib/fluent/fluent_log_event_router.rb +139 -0
 - data/lib/fluent/formatter.rb +23 -0
 - data/lib/fluent/input.rb +21 -0
 - data/lib/fluent/label.rb +46 -0
 - data/lib/fluent/load.rb +34 -0
 - data/lib/fluent/log/console_adapter.rb +66 -0
 - data/lib/fluent/log.rb +752 -0
 - data/lib/fluent/match.rb +187 -0
 - data/lib/fluent/mixin.rb +31 -0
 - data/lib/fluent/msgpack_factory.rb +111 -0
 - data/lib/fluent/oj_options.rb +61 -0
 - data/lib/fluent/output.rb +29 -0
 - data/lib/fluent/output_chain.rb +23 -0
 - data/lib/fluent/parser.rb +23 -0
 - data/lib/fluent/plugin/bare_output.rb +104 -0
 - data/lib/fluent/plugin/base.rb +214 -0
 - data/lib/fluent/plugin/buf_file.rb +242 -0
 - data/lib/fluent/plugin/buf_file_single.rb +254 -0
 - data/lib/fluent/plugin/buf_memory.rb +34 -0
 - data/lib/fluent/plugin/buffer/chunk.rb +240 -0
 - data/lib/fluent/plugin/buffer/file_chunk.rb +413 -0
 - data/lib/fluent/plugin/buffer/file_single_chunk.rb +310 -0
 - data/lib/fluent/plugin/buffer/memory_chunk.rb +91 -0
 - data/lib/fluent/plugin/buffer.rb +941 -0
 - data/lib/fluent/plugin/compressable.rb +96 -0
 - data/lib/fluent/plugin/exec_util.rb +22 -0
 - data/lib/fluent/plugin/file_util.rb +22 -0
 - data/lib/fluent/plugin/filter.rb +127 -0
 - data/lib/fluent/plugin/filter_grep.rb +189 -0
 - data/lib/fluent/plugin/filter_parser.rb +130 -0
 - data/lib/fluent/plugin/filter_record_transformer.rb +324 -0
 - data/lib/fluent/plugin/filter_stdout.rb +53 -0
 - data/lib/fluent/plugin/formatter.rb +75 -0
 - data/lib/fluent/plugin/formatter_csv.rb +78 -0
 - data/lib/fluent/plugin/formatter_hash.rb +35 -0
 - data/lib/fluent/plugin/formatter_json.rb +59 -0
 - data/lib/fluent/plugin/formatter_ltsv.rb +44 -0
 - data/lib/fluent/plugin/formatter_msgpack.rb +33 -0
 - data/lib/fluent/plugin/formatter_out_file.rb +53 -0
 - data/lib/fluent/plugin/formatter_single_value.rb +36 -0
 - data/lib/fluent/plugin/formatter_stdout.rb +76 -0
 - data/lib/fluent/plugin/formatter_tsv.rb +40 -0
 - data/lib/fluent/plugin/in_debug_agent.rb +71 -0
 - data/lib/fluent/plugin/in_dummy.rb +18 -0
 - data/lib/fluent/plugin/in_exec.rb +110 -0
 - data/lib/fluent/plugin/in_forward.rb +473 -0
 - data/lib/fluent/plugin/in_gc_stat.rb +72 -0
 - data/lib/fluent/plugin/in_http.rb +677 -0
 - data/lib/fluent/plugin/in_monitor_agent.rb +412 -0
 - data/lib/fluent/plugin/in_object_space.rb +93 -0
 - data/lib/fluent/plugin/in_sample.rb +141 -0
 - data/lib/fluent/plugin/in_syslog.rb +276 -0
 - data/lib/fluent/plugin/in_tail/group_watch.rb +204 -0
 - data/lib/fluent/plugin/in_tail/position_file.rb +269 -0
 - data/lib/fluent/plugin/in_tail.rb +1299 -0
 - data/lib/fluent/plugin/in_tcp.rb +226 -0
 - data/lib/fluent/plugin/in_udp.rb +92 -0
 - data/lib/fluent/plugin/in_unix.rb +195 -0
 - data/lib/fluent/plugin/input.rb +75 -0
 - data/lib/fluent/plugin/metrics.rb +119 -0
 - data/lib/fluent/plugin/metrics_local.rb +96 -0
 - data/lib/fluent/plugin/multi_output.rb +195 -0
 - data/lib/fluent/plugin/out_copy.rb +120 -0
 - data/lib/fluent/plugin/out_exec.rb +105 -0
 - data/lib/fluent/plugin/out_exec_filter.rb +319 -0
 - data/lib/fluent/plugin/out_file.rb +340 -0
 - data/lib/fluent/plugin/out_forward/ack_handler.rb +176 -0
 - data/lib/fluent/plugin/out_forward/connection_manager.rb +113 -0
 - data/lib/fluent/plugin/out_forward/error.rb +28 -0
 - data/lib/fluent/plugin/out_forward/failure_detector.rb +84 -0
 - data/lib/fluent/plugin/out_forward/handshake_protocol.rb +125 -0
 - data/lib/fluent/plugin/out_forward/load_balancer.rb +114 -0
 - data/lib/fluent/plugin/out_forward/socket_cache.rb +142 -0
 - data/lib/fluent/plugin/out_forward.rb +826 -0
 - data/lib/fluent/plugin/out_http.rb +275 -0
 - data/lib/fluent/plugin/out_null.rb +74 -0
 - data/lib/fluent/plugin/out_relabel.rb +32 -0
 - data/lib/fluent/plugin/out_roundrobin.rb +84 -0
 - data/lib/fluent/plugin/out_secondary_file.rb +148 -0
 - data/lib/fluent/plugin/out_stdout.rb +74 -0
 - data/lib/fluent/plugin/out_stream.rb +130 -0
 - data/lib/fluent/plugin/output.rb +1603 -0
 - data/lib/fluent/plugin/owned_by_mixin.rb +41 -0
 - data/lib/fluent/plugin/parser.rb +274 -0
 - data/lib/fluent/plugin/parser_apache.rb +28 -0
 - data/lib/fluent/plugin/parser_apache2.rb +88 -0
 - data/lib/fluent/plugin/parser_apache_error.rb +26 -0
 - data/lib/fluent/plugin/parser_csv.rb +114 -0
 - data/lib/fluent/plugin/parser_json.rb +96 -0
 - data/lib/fluent/plugin/parser_ltsv.rb +51 -0
 - data/lib/fluent/plugin/parser_msgpack.rb +50 -0
 - data/lib/fluent/plugin/parser_multiline.rb +152 -0
 - data/lib/fluent/plugin/parser_nginx.rb +28 -0
 - data/lib/fluent/plugin/parser_none.rb +36 -0
 - data/lib/fluent/plugin/parser_regexp.rb +68 -0
 - data/lib/fluent/plugin/parser_syslog.rb +496 -0
 - data/lib/fluent/plugin/parser_tsv.rb +42 -0
 - data/lib/fluent/plugin/sd_file.rb +156 -0
 - data/lib/fluent/plugin/sd_srv.rb +135 -0
 - data/lib/fluent/plugin/sd_static.rb +58 -0
 - data/lib/fluent/plugin/service_discovery.rb +65 -0
 - data/lib/fluent/plugin/socket_util.rb +22 -0
 - data/lib/fluent/plugin/storage.rb +84 -0
 - data/lib/fluent/plugin/storage_local.rb +162 -0
 - data/lib/fluent/plugin/string_util.rb +22 -0
 - data/lib/fluent/plugin.rb +206 -0
 - data/lib/fluent/plugin_helper/cert_option.rb +191 -0
 - data/lib/fluent/plugin_helper/child_process.rb +369 -0
 - data/lib/fluent/plugin_helper/compat_parameters.rb +343 -0
 - data/lib/fluent/plugin_helper/counter.rb +51 -0
 - data/lib/fluent/plugin_helper/event_emitter.rb +100 -0
 - data/lib/fluent/plugin_helper/event_loop.rb +170 -0
 - data/lib/fluent/plugin_helper/extract.rb +104 -0
 - data/lib/fluent/plugin_helper/formatter.rb +147 -0
 - data/lib/fluent/plugin_helper/http_server/app.rb +79 -0
 - data/lib/fluent/plugin_helper/http_server/compat/server.rb +92 -0
 - data/lib/fluent/plugin_helper/http_server/compat/ssl_context_extractor.rb +52 -0
 - data/lib/fluent/plugin_helper/http_server/compat/webrick_handler.rb +58 -0
 - data/lib/fluent/plugin_helper/http_server/methods.rb +35 -0
 - data/lib/fluent/plugin_helper/http_server/request.rb +42 -0
 - data/lib/fluent/plugin_helper/http_server/router.rb +54 -0
 - data/lib/fluent/plugin_helper/http_server/server.rb +94 -0
 - data/lib/fluent/plugin_helper/http_server/ssl_context_builder.rb +41 -0
 - data/lib/fluent/plugin_helper/http_server.rb +135 -0
 - data/lib/fluent/plugin_helper/inject.rb +154 -0
 - data/lib/fluent/plugin_helper/metrics.rb +129 -0
 - data/lib/fluent/plugin_helper/parser.rb +147 -0
 - data/lib/fluent/plugin_helper/record_accessor.rb +207 -0
 - data/lib/fluent/plugin_helper/retry_state.rb +219 -0
 - data/lib/fluent/plugin_helper/server.rb +828 -0
 - data/lib/fluent/plugin_helper/service_discovery/manager.rb +146 -0
 - data/lib/fluent/plugin_helper/service_discovery/round_robin_balancer.rb +43 -0
 - data/lib/fluent/plugin_helper/service_discovery.rb +125 -0
 - data/lib/fluent/plugin_helper/socket.rb +288 -0
 - data/lib/fluent/plugin_helper/socket_option.rb +98 -0
 - data/lib/fluent/plugin_helper/storage.rb +349 -0
 - data/lib/fluent/plugin_helper/thread.rb +180 -0
 - data/lib/fluent/plugin_helper/timer.rb +92 -0
 - data/lib/fluent/plugin_helper.rb +75 -0
 - data/lib/fluent/plugin_id.rb +93 -0
 - data/lib/fluent/process.rb +22 -0
 - data/lib/fluent/registry.rb +117 -0
 - data/lib/fluent/root_agent.rb +372 -0
 - data/lib/fluent/rpc.rb +95 -0
 - data/lib/fluent/static_config_analysis.rb +194 -0
 - data/lib/fluent/supervisor.rb +1076 -0
 - data/lib/fluent/system_config.rb +189 -0
 - data/lib/fluent/test/base.rb +78 -0
 - data/lib/fluent/test/driver/base.rb +231 -0
 - data/lib/fluent/test/driver/base_owned.rb +83 -0
 - data/lib/fluent/test/driver/base_owner.rb +135 -0
 - data/lib/fluent/test/driver/event_feeder.rb +98 -0
 - data/lib/fluent/test/driver/filter.rb +61 -0
 - data/lib/fluent/test/driver/formatter.rb +30 -0
 - data/lib/fluent/test/driver/input.rb +31 -0
 - data/lib/fluent/test/driver/multi_output.rb +53 -0
 - data/lib/fluent/test/driver/output.rb +102 -0
 - data/lib/fluent/test/driver/parser.rb +30 -0
 - data/lib/fluent/test/driver/storage.rb +30 -0
 - data/lib/fluent/test/driver/test_event_router.rb +45 -0
 - data/lib/fluent/test/filter_test.rb +77 -0
 - data/lib/fluent/test/formatter_test.rb +65 -0
 - data/lib/fluent/test/helpers.rb +134 -0
 - data/lib/fluent/test/input_test.rb +174 -0
 - data/lib/fluent/test/log.rb +79 -0
 - data/lib/fluent/test/output_test.rb +156 -0
 - data/lib/fluent/test/parser_test.rb +70 -0
 - data/lib/fluent/test/startup_shutdown.rb +44 -0
 - data/lib/fluent/test.rb +58 -0
 - data/lib/fluent/time.rb +512 -0
 - data/lib/fluent/timezone.rb +171 -0
 - data/lib/fluent/tls.rb +81 -0
 - data/lib/fluent/unique_id.rb +39 -0
 - data/lib/fluent/variable_store.rb +40 -0
 - data/lib/fluent/version.rb +21 -0
 - data/lib/fluent/win32api.rb +38 -0
 - data/lib/fluent/winsvc.rb +100 -0
 - data/templates/new_gem/Gemfile +3 -0
 - data/templates/new_gem/README.md.erb +43 -0
 - data/templates/new_gem/Rakefile +13 -0
 - data/templates/new_gem/fluent-plugin.gemspec.erb +27 -0
 - data/templates/new_gem/lib/fluent/plugin/filter.rb.erb +14 -0
 - data/templates/new_gem/lib/fluent/plugin/formatter.rb.erb +14 -0
 - data/templates/new_gem/lib/fluent/plugin/input.rb.erb +11 -0
 - data/templates/new_gem/lib/fluent/plugin/output.rb.erb +11 -0
 - data/templates/new_gem/lib/fluent/plugin/parser.rb.erb +15 -0
 - data/templates/new_gem/lib/fluent/plugin/storage.rb.erb +40 -0
 - data/templates/new_gem/test/helper.rb.erb +7 -0
 - data/templates/new_gem/test/plugin/test_filter.rb.erb +18 -0
 - data/templates/new_gem/test/plugin/test_formatter.rb.erb +18 -0
 - data/templates/new_gem/test/plugin/test_input.rb.erb +18 -0
 - data/templates/new_gem/test/plugin/test_output.rb.erb +18 -0
 - data/templates/new_gem/test/plugin/test_parser.rb.erb +18 -0
 - data/templates/new_gem/test/plugin/test_storage.rb.erb +18 -0
 - data/templates/plugin_config_formatter/param.md-compact.erb +25 -0
 - data/templates/plugin_config_formatter/param.md-table.erb +10 -0
 - data/templates/plugin_config_formatter/param.md.erb +34 -0
 - data/templates/plugin_config_formatter/section.md.erb +12 -0
 - data/test/command/test_binlog_reader.rb +362 -0
 - data/test/command/test_ca_generate.rb +70 -0
 - data/test/command/test_cap_ctl.rb +100 -0
 - data/test/command/test_cat.rb +128 -0
 - data/test/command/test_ctl.rb +56 -0
 - data/test/command/test_fluentd.rb +1291 -0
 - data/test/command/test_plugin_config_formatter.rb +397 -0
 - data/test/command/test_plugin_generator.rb +109 -0
 - data/test/compat/test_calls_super.rb +166 -0
 - data/test/compat/test_parser.rb +92 -0
 - data/test/config/assertions.rb +42 -0
 - data/test/config/test_config_parser.rb +551 -0
 - data/test/config/test_configurable.rb +1784 -0
 - data/test/config/test_configure_proxy.rb +604 -0
 - data/test/config/test_dsl.rb +415 -0
 - data/test/config/test_element.rb +518 -0
 - data/test/config/test_literal_parser.rb +309 -0
 - data/test/config/test_plugin_configuration.rb +56 -0
 - data/test/config/test_section.rb +191 -0
 - data/test/config/test_system_config.rb +195 -0
 - data/test/config/test_types.rb +408 -0
 - data/test/counter/test_client.rb +563 -0
 - data/test/counter/test_error.rb +44 -0
 - data/test/counter/test_mutex_hash.rb +179 -0
 - data/test/counter/test_server.rb +589 -0
 - data/test/counter/test_store.rb +258 -0
 - data/test/counter/test_validator.rb +137 -0
 - data/test/helper.rb +155 -0
 - data/test/helpers/fuzzy_assert.rb +89 -0
 - data/test/helpers/process_extenstion.rb +33 -0
 - data/test/log/test_console_adapter.rb +110 -0
 - data/test/plugin/data/2010/01/20100102-030405.log +0 -0
 - data/test/plugin/data/2010/01/20100102-030406.log +0 -0
 - data/test/plugin/data/2010/01/20100102.log +0 -0
 - data/test/plugin/data/log/bar +0 -0
 - data/test/plugin/data/log/foo/bar.log +0 -0
 - data/test/plugin/data/log/foo/bar2 +0 -0
 - data/test/plugin/data/log/test.log +0 -0
 - data/test/plugin/data/sd_file/config +11 -0
 - data/test/plugin/data/sd_file/config.json +17 -0
 - data/test/plugin/data/sd_file/config.yaml +11 -0
 - data/test/plugin/data/sd_file/config.yml +11 -0
 - data/test/plugin/data/sd_file/invalid_config.yml +7 -0
 - data/test/plugin/in_tail/test_fifo.rb +121 -0
 - data/test/plugin/in_tail/test_io_handler.rb +150 -0
 - data/test/plugin/in_tail/test_position_file.rb +346 -0
 - data/test/plugin/out_forward/test_ack_handler.rb +140 -0
 - data/test/plugin/out_forward/test_connection_manager.rb +145 -0
 - data/test/plugin/out_forward/test_handshake_protocol.rb +112 -0
 - data/test/plugin/out_forward/test_load_balancer.rb +106 -0
 - data/test/plugin/out_forward/test_socket_cache.rb +174 -0
 - data/test/plugin/test_bare_output.rb +131 -0
 - data/test/plugin/test_base.rb +247 -0
 - data/test/plugin/test_buf_file.rb +1314 -0
 - data/test/plugin/test_buf_file_single.rb +898 -0
 - data/test/plugin/test_buf_memory.rb +42 -0
 - data/test/plugin/test_buffer.rb +1434 -0
 - data/test/plugin/test_buffer_chunk.rb +209 -0
 - data/test/plugin/test_buffer_file_chunk.rb +871 -0
 - data/test/plugin/test_buffer_file_single_chunk.rb +611 -0
 - data/test/plugin/test_buffer_memory_chunk.rb +339 -0
 - data/test/plugin/test_compressable.rb +87 -0
 - data/test/plugin/test_file_util.rb +96 -0
 - data/test/plugin/test_filter.rb +368 -0
 - data/test/plugin/test_filter_grep.rb +697 -0
 - data/test/plugin/test_filter_parser.rb +731 -0
 - data/test/plugin/test_filter_record_transformer.rb +577 -0
 - data/test/plugin/test_filter_stdout.rb +207 -0
 - data/test/plugin/test_formatter_csv.rb +136 -0
 - data/test/plugin/test_formatter_hash.rb +38 -0
 - data/test/plugin/test_formatter_json.rb +61 -0
 - data/test/plugin/test_formatter_ltsv.rb +70 -0
 - data/test/plugin/test_formatter_msgpack.rb +28 -0
 - data/test/plugin/test_formatter_out_file.rb +116 -0
 - data/test/plugin/test_formatter_single_value.rb +44 -0
 - data/test/plugin/test_formatter_tsv.rb +76 -0
 - data/test/plugin/test_in_debug_agent.rb +49 -0
 - data/test/plugin/test_in_exec.rb +261 -0
 - data/test/plugin/test_in_forward.rb +1178 -0
 - data/test/plugin/test_in_gc_stat.rb +62 -0
 - data/test/plugin/test_in_http.rb +1102 -0
 - data/test/plugin/test_in_monitor_agent.rb +922 -0
 - data/test/plugin/test_in_object_space.rb +66 -0
 - data/test/plugin/test_in_sample.rb +190 -0
 - data/test/plugin/test_in_syslog.rb +505 -0
 - data/test/plugin/test_in_tail.rb +3125 -0
 - data/test/plugin/test_in_tcp.rb +328 -0
 - data/test/plugin/test_in_udp.rb +296 -0
 - data/test/plugin/test_in_unix.rb +181 -0
 - data/test/plugin/test_input.rb +137 -0
 - data/test/plugin/test_metadata.rb +89 -0
 - data/test/plugin/test_metrics.rb +294 -0
 - data/test/plugin/test_metrics_local.rb +96 -0
 - data/test/plugin/test_multi_output.rb +204 -0
 - data/test/plugin/test_out_copy.rb +308 -0
 - data/test/plugin/test_out_exec.rb +312 -0
 - data/test/plugin/test_out_exec_filter.rb +606 -0
 - data/test/plugin/test_out_file.rb +1038 -0
 - data/test/plugin/test_out_forward.rb +1361 -0
 - data/test/plugin/test_out_http.rb +429 -0
 - data/test/plugin/test_out_null.rb +105 -0
 - data/test/plugin/test_out_relabel.rb +28 -0
 - data/test/plugin/test_out_roundrobin.rb +146 -0
 - data/test/plugin/test_out_secondary_file.rb +458 -0
 - data/test/plugin/test_out_stdout.rb +205 -0
 - data/test/plugin/test_out_stream.rb +103 -0
 - data/test/plugin/test_output.rb +1334 -0
 - data/test/plugin/test_output_as_buffered.rb +2024 -0
 - data/test/plugin/test_output_as_buffered_backup.rb +363 -0
 - data/test/plugin/test_output_as_buffered_compress.rb +179 -0
 - data/test/plugin/test_output_as_buffered_overflow.rb +250 -0
 - data/test/plugin/test_output_as_buffered_retries.rb +966 -0
 - data/test/plugin/test_output_as_buffered_secondary.rb +882 -0
 - data/test/plugin/test_output_as_standard.rb +374 -0
 - data/test/plugin/test_owned_by.rb +34 -0
 - data/test/plugin/test_parser.rb +399 -0
 - data/test/plugin/test_parser_apache.rb +42 -0
 - data/test/plugin/test_parser_apache2.rb +47 -0
 - data/test/plugin/test_parser_apache_error.rb +45 -0
 - data/test/plugin/test_parser_csv.rb +200 -0
 - data/test/plugin/test_parser_json.rb +138 -0
 - data/test/plugin/test_parser_labeled_tsv.rb +160 -0
 - data/test/plugin/test_parser_multiline.rb +111 -0
 - data/test/plugin/test_parser_nginx.rb +88 -0
 - data/test/plugin/test_parser_none.rb +52 -0
 - data/test/plugin/test_parser_regexp.rb +284 -0
 - data/test/plugin/test_parser_syslog.rb +650 -0
 - data/test/plugin/test_parser_tsv.rb +122 -0
 - data/test/plugin/test_sd_file.rb +228 -0
 - data/test/plugin/test_sd_srv.rb +230 -0
 - data/test/plugin/test_storage.rb +166 -0
 - data/test/plugin/test_storage_local.rb +335 -0
 - data/test/plugin/test_string_util.rb +26 -0
 - data/test/plugin_helper/data/cert/cert-key.pem +27 -0
 - data/test/plugin_helper/data/cert/cert-with-CRLF.pem +19 -0
 - data/test/plugin_helper/data/cert/cert-with-no-newline.pem +19 -0
 - data/test/plugin_helper/data/cert/cert.pem +19 -0
 - data/test/plugin_helper/data/cert/cert_chains/ca-cert-key.pem +27 -0
 - data/test/plugin_helper/data/cert/cert_chains/ca-cert.pem +20 -0
 - data/test/plugin_helper/data/cert/cert_chains/cert-key.pem +27 -0
 - data/test/plugin_helper/data/cert/cert_chains/cert.pem +40 -0
 - data/test/plugin_helper/data/cert/empty.pem +0 -0
 - data/test/plugin_helper/data/cert/generate_cert.rb +125 -0
 - data/test/plugin_helper/data/cert/with_ca/ca-cert-key-pass.pem +30 -0
 - data/test/plugin_helper/data/cert/with_ca/ca-cert-key.pem +27 -0
 - data/test/plugin_helper/data/cert/with_ca/ca-cert-pass.pem +20 -0
 - data/test/plugin_helper/data/cert/with_ca/ca-cert.pem +20 -0
 - data/test/plugin_helper/data/cert/with_ca/cert-key-pass.pem +30 -0
 - data/test/plugin_helper/data/cert/with_ca/cert-key.pem +27 -0
 - data/test/plugin_helper/data/cert/with_ca/cert-pass.pem +21 -0
 - data/test/plugin_helper/data/cert/with_ca/cert.pem +21 -0
 - data/test/plugin_helper/data/cert/without_ca/cert-key-pass.pem +30 -0
 - data/test/plugin_helper/data/cert/without_ca/cert-key.pem +27 -0
 - data/test/plugin_helper/data/cert/without_ca/cert-pass.pem +20 -0
 - data/test/plugin_helper/data/cert/without_ca/cert.pem +20 -0
 - data/test/plugin_helper/http_server/test_app.rb +65 -0
 - data/test/plugin_helper/http_server/test_route.rb +32 -0
 - data/test/plugin_helper/service_discovery/test_manager.rb +93 -0
 - data/test/plugin_helper/service_discovery/test_round_robin_balancer.rb +21 -0
 - data/test/plugin_helper/test_cert_option.rb +25 -0
 - data/test/plugin_helper/test_child_process.rb +862 -0
 - data/test/plugin_helper/test_compat_parameters.rb +358 -0
 - data/test/plugin_helper/test_event_emitter.rb +80 -0
 - data/test/plugin_helper/test_event_loop.rb +52 -0
 - data/test/plugin_helper/test_extract.rb +194 -0
 - data/test/plugin_helper/test_formatter.rb +255 -0
 - data/test/plugin_helper/test_http_server_helper.rb +372 -0
 - data/test/plugin_helper/test_inject.rb +561 -0
 - data/test/plugin_helper/test_metrics.rb +137 -0
 - data/test/plugin_helper/test_parser.rb +264 -0
 - data/test/plugin_helper/test_record_accessor.rb +238 -0
 - data/test/plugin_helper/test_retry_state.rb +1006 -0
 - data/test/plugin_helper/test_server.rb +1895 -0
 - data/test/plugin_helper/test_service_discovery.rb +165 -0
 - data/test/plugin_helper/test_socket.rb +146 -0
 - data/test/plugin_helper/test_storage.rb +542 -0
 - data/test/plugin_helper/test_thread.rb +164 -0
 - data/test/plugin_helper/test_timer.rb +130 -0
 - data/test/scripts/exec_script.rb +32 -0
 - data/test/scripts/fluent/plugin/formatter1/formatter_test1.rb +7 -0
 - data/test/scripts/fluent/plugin/formatter2/formatter_test2.rb +7 -0
 - data/test/scripts/fluent/plugin/formatter_known.rb +8 -0
 - data/test/scripts/fluent/plugin/out_test.rb +81 -0
 - data/test/scripts/fluent/plugin/out_test2.rb +80 -0
 - data/test/scripts/fluent/plugin/parser_known.rb +4 -0
 - data/test/test_capability.rb +74 -0
 - data/test/test_clock.rb +164 -0
 - data/test/test_config.rb +369 -0
 - data/test/test_configdsl.rb +148 -0
 - data/test/test_daemonizer.rb +91 -0
 - data/test/test_engine.rb +203 -0
 - data/test/test_event.rb +531 -0
 - data/test/test_event_router.rb +348 -0
 - data/test/test_event_time.rb +199 -0
 - data/test/test_file_wrapper.rb +53 -0
 - data/test/test_filter.rb +121 -0
 - data/test/test_fluent_log_event_router.rb +99 -0
 - data/test/test_formatter.rb +369 -0
 - data/test/test_input.rb +31 -0
 - data/test/test_log.rb +1076 -0
 - data/test/test_match.rb +148 -0
 - data/test/test_mixin.rb +351 -0
 - data/test/test_msgpack_factory.rb +50 -0
 - data/test/test_oj_options.rb +55 -0
 - data/test/test_output.rb +278 -0
 - data/test/test_plugin.rb +251 -0
 - data/test/test_plugin_classes.rb +370 -0
 - data/test/test_plugin_helper.rb +81 -0
 - data/test/test_plugin_id.rb +119 -0
 - data/test/test_process.rb +14 -0
 - data/test/test_root_agent.rb +951 -0
 - data/test/test_static_config_analysis.rb +177 -0
 - data/test/test_supervisor.rb +821 -0
 - data/test/test_test_drivers.rb +136 -0
 - data/test/test_time_formatter.rb +301 -0
 - data/test/test_time_parser.rb +362 -0
 - data/test/test_tls.rb +65 -0
 - data/test/test_unique_id.rb +47 -0
 - data/test/test_variable_store.rb +65 -0
 - metadata +1183 -0
 
| 
         @@ -0,0 +1,1076 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            #
         
     | 
| 
      
 2 
     | 
    
         
            +
            # Fluentd
         
     | 
| 
      
 3 
     | 
    
         
            +
            #
         
     | 
| 
      
 4 
     | 
    
         
            +
            #    Licensed under the Apache License, Version 2.0 (the "License");
         
     | 
| 
      
 5 
     | 
    
         
            +
            #    you may not use this file except in compliance with the License.
         
     | 
| 
      
 6 
     | 
    
         
            +
            #    You may obtain a copy of the License at
         
     | 
| 
      
 7 
     | 
    
         
            +
            #
         
     | 
| 
      
 8 
     | 
    
         
            +
            #        http://www.apache.org/licenses/LICENSE-2.0
         
     | 
| 
      
 9 
     | 
    
         
            +
            #
         
     | 
| 
      
 10 
     | 
    
         
            +
            #    Unless required by applicable law or agreed to in writing, software
         
     | 
| 
      
 11 
     | 
    
         
            +
            #    distributed under the License is distributed on an "AS IS" BASIS,
         
     | 
| 
      
 12 
     | 
    
         
            +
            #    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
         
     | 
| 
      
 13 
     | 
    
         
            +
            #    See the License for the specific language governing permissions and
         
     | 
| 
      
 14 
     | 
    
         
            +
            #    limitations under the License.
         
     | 
| 
      
 15 
     | 
    
         
            +
            #
         
     | 
| 
      
 16 
     | 
    
         
            +
             
     | 
| 
      
 17 
     | 
    
         
            +
            require 'fileutils'
         
     | 
| 
      
 18 
     | 
    
         
            +
            require 'open3'
         
     | 
| 
      
 19 
     | 
    
         
            +
            require 'pathname'
         
     | 
| 
      
 20 
     | 
    
         
            +
             
     | 
| 
      
 21 
     | 
    
         
            +
            require 'fluent/config'
         
     | 
| 
      
 22 
     | 
    
         
            +
            require 'fluent/counter'
         
     | 
| 
      
 23 
     | 
    
         
            +
            require 'fluent/env'
         
     | 
| 
      
 24 
     | 
    
         
            +
            require 'fluent/engine'
         
     | 
| 
      
 25 
     | 
    
         
            +
            require 'fluent/error'
         
     | 
| 
      
 26 
     | 
    
         
            +
            require 'fluent/log'
         
     | 
| 
      
 27 
     | 
    
         
            +
            require 'fluent/plugin'
         
     | 
| 
      
 28 
     | 
    
         
            +
            require 'fluent/rpc'
         
     | 
| 
      
 29 
     | 
    
         
            +
            require 'fluent/system_config'
         
     | 
| 
      
 30 
     | 
    
         
            +
            require 'fluent/msgpack_factory'
         
     | 
| 
      
 31 
     | 
    
         
            +
            require 'fluent/variable_store'
         
     | 
| 
      
 32 
     | 
    
         
            +
            require 'serverengine'
         
     | 
| 
      
 33 
     | 
    
         
            +
             
     | 
| 
      
 34 
     | 
    
         
            +
            if Fluent.windows?
         
     | 
| 
      
 35 
     | 
    
         
            +
              require 'win32/ipc'
         
     | 
| 
      
 36 
     | 
    
         
            +
              require 'win32/event'
         
     | 
| 
      
 37 
     | 
    
         
            +
            end
         
     | 
| 
      
 38 
     | 
    
         
            +
             
     | 
| 
      
 39 
     | 
    
         
            +
            module Fluent
         
     | 
| 
      
 40 
     | 
    
         
            +
              module ServerModule
         
     | 
| 
      
 41 
     | 
    
         
            +
                def before_run
         
     | 
| 
      
 42 
     | 
    
         
            +
                  @fluentd_conf = config[:fluentd_conf]
         
     | 
| 
      
 43 
     | 
    
         
            +
                  @rpc_endpoint = nil
         
     | 
| 
      
 44 
     | 
    
         
            +
                  @rpc_server = nil
         
     | 
| 
      
 45 
     | 
    
         
            +
                  @counter = nil
         
     | 
| 
      
 46 
     | 
    
         
            +
             
     | 
| 
      
 47 
     | 
    
         
            +
                  @fluentd_lock_dir = Dir.mktmpdir("fluentd-lock-")
         
     | 
| 
      
 48 
     | 
    
         
            +
                  ENV['FLUENTD_LOCK_DIR'] = @fluentd_lock_dir
         
     | 
| 
      
 49 
     | 
    
         
            +
             
     | 
| 
      
 50 
     | 
    
         
            +
                  if config[:rpc_endpoint]
         
     | 
| 
      
 51 
     | 
    
         
            +
                    @rpc_endpoint = config[:rpc_endpoint]
         
     | 
| 
      
 52 
     | 
    
         
            +
                    @enable_get_dump = config[:enable_get_dump]
         
     | 
| 
      
 53 
     | 
    
         
            +
                    run_rpc_server
         
     | 
| 
      
 54 
     | 
    
         
            +
                  end
         
     | 
| 
      
 55 
     | 
    
         
            +
             
     | 
| 
      
 56 
     | 
    
         
            +
                  if Fluent.windows?
         
     | 
| 
      
 57 
     | 
    
         
            +
                    install_windows_event_handler
         
     | 
| 
      
 58 
     | 
    
         
            +
                  else
         
     | 
| 
      
 59 
     | 
    
         
            +
                    install_supervisor_signal_handlers
         
     | 
| 
      
 60 
     | 
    
         
            +
                  end
         
     | 
| 
      
 61 
     | 
    
         
            +
             
     | 
| 
      
 62 
     | 
    
         
            +
                  if counter = config[:counter_server]
         
     | 
| 
      
 63 
     | 
    
         
            +
                    run_counter_server(counter)
         
     | 
| 
      
 64 
     | 
    
         
            +
                  end
         
     | 
| 
      
 65 
     | 
    
         
            +
             
     | 
| 
      
 66 
     | 
    
         
            +
                  if config[:disable_shared_socket]
         
     | 
| 
      
 67 
     | 
    
         
            +
                    $log.info "shared socket for multiple workers is disabled"
         
     | 
| 
      
 68 
     | 
    
         
            +
                  else
         
     | 
| 
      
 69 
     | 
    
         
            +
                    server = ServerEngine::SocketManager::Server.open
         
     | 
| 
      
 70 
     | 
    
         
            +
                    ENV['SERVERENGINE_SOCKETMANAGER_PATH'] = server.path.to_s
         
     | 
| 
      
 71 
     | 
    
         
            +
                  end
         
     | 
| 
      
 72 
     | 
    
         
            +
                end
         
     | 
| 
      
 73 
     | 
    
         
            +
             
     | 
| 
      
 74 
     | 
    
         
            +
                def after_run
         
     | 
| 
      
 75 
     | 
    
         
            +
                  stop_windows_event_thread if Fluent.windows?
         
     | 
| 
      
 76 
     | 
    
         
            +
                  stop_rpc_server if @rpc_endpoint
         
     | 
| 
      
 77 
     | 
    
         
            +
                  stop_counter_server if @counter
         
     | 
| 
      
 78 
     | 
    
         
            +
                  cleanup_lock_dir
         
     | 
| 
      
 79 
     | 
    
         
            +
                  Fluent::Supervisor.cleanup_resources
         
     | 
| 
      
 80 
     | 
    
         
            +
                end
         
     | 
| 
      
 81 
     | 
    
         
            +
             
     | 
| 
      
 82 
     | 
    
         
            +
                def cleanup_lock_dir
         
     | 
| 
      
 83 
     | 
    
         
            +
                  FileUtils.rm(Dir.glob(File.join(@fluentd_lock_dir, "fluentd-*.lock")))
         
     | 
| 
      
 84 
     | 
    
         
            +
                  FileUtils.rmdir(@fluentd_lock_dir)
         
     | 
| 
      
 85 
     | 
    
         
            +
                end
         
     | 
| 
      
 86 
     | 
    
         
            +
             
     | 
| 
      
 87 
     | 
    
         
            +
                def run_rpc_server
         
     | 
| 
      
 88 
     | 
    
         
            +
                  @rpc_server = RPC::Server.new(@rpc_endpoint, $log)
         
     | 
| 
      
 89 
     | 
    
         
            +
             
     | 
| 
      
 90 
     | 
    
         
            +
                  # built-in RPC for signals
         
     | 
| 
      
 91 
     | 
    
         
            +
                  @rpc_server.mount_proc('/api/processes.interruptWorkers') { |req, res|
         
     | 
| 
      
 92 
     | 
    
         
            +
                    $log.debug "fluentd RPC got /api/processes.interruptWorkers request"
         
     | 
| 
      
 93 
     | 
    
         
            +
                    Process.kill :INT, Process.pid
         
     | 
| 
      
 94 
     | 
    
         
            +
                    nil
         
     | 
| 
      
 95 
     | 
    
         
            +
                  }
         
     | 
| 
      
 96 
     | 
    
         
            +
                  @rpc_server.mount_proc('/api/processes.killWorkers') { |req, res|
         
     | 
| 
      
 97 
     | 
    
         
            +
                    $log.debug "fluentd RPC got /api/processes.killWorkers request"
         
     | 
| 
      
 98 
     | 
    
         
            +
                    Process.kill :TERM, Process.pid
         
     | 
| 
      
 99 
     | 
    
         
            +
                    nil
         
     | 
| 
      
 100 
     | 
    
         
            +
                  }
         
     | 
| 
      
 101 
     | 
    
         
            +
                  @rpc_server.mount_proc('/api/processes.flushBuffersAndKillWorkers') { |req, res|
         
     | 
| 
      
 102 
     | 
    
         
            +
                    $log.debug "fluentd RPC got /api/processes.flushBuffersAndKillWorkers request"
         
     | 
| 
      
 103 
     | 
    
         
            +
                    if Fluent.windows?
         
     | 
| 
      
 104 
     | 
    
         
            +
                      supervisor_sigusr1_handler
         
     | 
| 
      
 105 
     | 
    
         
            +
                      stop(true)
         
     | 
| 
      
 106 
     | 
    
         
            +
                    else
         
     | 
| 
      
 107 
     | 
    
         
            +
                      Process.kill :USR1, Process.pid
         
     | 
| 
      
 108 
     | 
    
         
            +
                      Process.kill :TERM, Process.pid
         
     | 
| 
      
 109 
     | 
    
         
            +
                    end
         
     | 
| 
      
 110 
     | 
    
         
            +
                    nil
         
     | 
| 
      
 111 
     | 
    
         
            +
                  }
         
     | 
| 
      
 112 
     | 
    
         
            +
                  @rpc_server.mount_proc('/api/plugins.flushBuffers') { |req, res|
         
     | 
| 
      
 113 
     | 
    
         
            +
                    $log.debug "fluentd RPC got /api/plugins.flushBuffers request"
         
     | 
| 
      
 114 
     | 
    
         
            +
                    if Fluent.windows?
         
     | 
| 
      
 115 
     | 
    
         
            +
                      supervisor_sigusr1_handler
         
     | 
| 
      
 116 
     | 
    
         
            +
                    else
         
     | 
| 
      
 117 
     | 
    
         
            +
                      Process.kill :USR1, Process.pid
         
     | 
| 
      
 118 
     | 
    
         
            +
                    end
         
     | 
| 
      
 119 
     | 
    
         
            +
                    nil
         
     | 
| 
      
 120 
     | 
    
         
            +
                  }
         
     | 
| 
      
 121 
     | 
    
         
            +
                  @rpc_server.mount_proc('/api/config.reload') { |req, res|
         
     | 
| 
      
 122 
     | 
    
         
            +
                    $log.debug "fluentd RPC got /api/config.reload request"
         
     | 
| 
      
 123 
     | 
    
         
            +
                    if Fluent.windows?
         
     | 
| 
      
 124 
     | 
    
         
            +
                      # restart worker with auto restarting by killing
         
     | 
| 
      
 125 
     | 
    
         
            +
                      kill_worker
         
     | 
| 
      
 126 
     | 
    
         
            +
                    else
         
     | 
| 
      
 127 
     | 
    
         
            +
                      Process.kill :HUP, Process.pid
         
     | 
| 
      
 128 
     | 
    
         
            +
                    end
         
     | 
| 
      
 129 
     | 
    
         
            +
                    nil
         
     | 
| 
      
 130 
     | 
    
         
            +
                  }
         
     | 
| 
      
 131 
     | 
    
         
            +
                  @rpc_server.mount_proc('/api/config.dump') { |req, res|
         
     | 
| 
      
 132 
     | 
    
         
            +
                    $log.debug "fluentd RPC got /api/config.dump request"
         
     | 
| 
      
 133 
     | 
    
         
            +
                    $log.info "dump in-memory config"
         
     | 
| 
      
 134 
     | 
    
         
            +
                    supervisor_dump_config_handler
         
     | 
| 
      
 135 
     | 
    
         
            +
                    nil
         
     | 
| 
      
 136 
     | 
    
         
            +
                  }
         
     | 
| 
      
 137 
     | 
    
         
            +
             
     | 
| 
      
 138 
     | 
    
         
            +
                  @rpc_server.mount_proc('/api/config.gracefulReload') { |req, res|
         
     | 
| 
      
 139 
     | 
    
         
            +
                    $log.debug "fluentd RPC got /api/config.gracefulReload request"
         
     | 
| 
      
 140 
     | 
    
         
            +
                    if Fluent.windows?
         
     | 
| 
      
 141 
     | 
    
         
            +
                      supervisor_sigusr2_handler
         
     | 
| 
      
 142 
     | 
    
         
            +
                    else
         
     | 
| 
      
 143 
     | 
    
         
            +
                      Process.kill :USR2, Process.pid
         
     | 
| 
      
 144 
     | 
    
         
            +
                    end
         
     | 
| 
      
 145 
     | 
    
         
            +
             
     | 
| 
      
 146 
     | 
    
         
            +
                    nil
         
     | 
| 
      
 147 
     | 
    
         
            +
                  }
         
     | 
| 
      
 148 
     | 
    
         
            +
             
     | 
| 
      
 149 
     | 
    
         
            +
                  @rpc_server.mount_proc('/api/config.getDump') { |req, res|
         
     | 
| 
      
 150 
     | 
    
         
            +
                    $log.debug "fluentd RPC got /api/config.getDump request"
         
     | 
| 
      
 151 
     | 
    
         
            +
                    $log.info "get dump in-memory config via HTTP"
         
     | 
| 
      
 152 
     | 
    
         
            +
                    res.body = supervisor_get_dump_config_handler
         
     | 
| 
      
 153 
     | 
    
         
            +
                    [nil, nil, res]
         
     | 
| 
      
 154 
     | 
    
         
            +
                  } if @enable_get_dump
         
     | 
| 
      
 155 
     | 
    
         
            +
             
     | 
| 
      
 156 
     | 
    
         
            +
                  @rpc_server.start
         
     | 
| 
      
 157 
     | 
    
         
            +
                end
         
     | 
| 
      
 158 
     | 
    
         
            +
             
     | 
| 
      
 159 
     | 
    
         
            +
                def stop_rpc_server
         
     | 
| 
      
 160 
     | 
    
         
            +
                  @rpc_server.shutdown
         
     | 
| 
      
 161 
     | 
    
         
            +
                end
         
     | 
| 
      
 162 
     | 
    
         
            +
             
     | 
| 
      
 163 
     | 
    
         
            +
                def run_counter_server(counter_conf)
         
     | 
| 
      
 164 
     | 
    
         
            +
                  @counter = Fluent::Counter::Server.new(
         
     | 
| 
      
 165 
     | 
    
         
            +
                    counter_conf.scope,
         
     | 
| 
      
 166 
     | 
    
         
            +
                    {host: counter_conf.bind, port: counter_conf.port, log: $log, path: counter_conf.backup_path}
         
     | 
| 
      
 167 
     | 
    
         
            +
                  )
         
     | 
| 
      
 168 
     | 
    
         
            +
                  @counter.start
         
     | 
| 
      
 169 
     | 
    
         
            +
                end
         
     | 
| 
      
 170 
     | 
    
         
            +
             
     | 
| 
      
 171 
     | 
    
         
            +
                def stop_counter_server
         
     | 
| 
      
 172 
     | 
    
         
            +
                  @counter.stop
         
     | 
| 
      
 173 
     | 
    
         
            +
                end
         
     | 
| 
      
 174 
     | 
    
         
            +
             
     | 
| 
      
 175 
     | 
    
         
            +
                def install_supervisor_signal_handlers
         
     | 
| 
      
 176 
     | 
    
         
            +
                  return if Fluent.windows?
         
     | 
| 
      
 177 
     | 
    
         
            +
             
     | 
| 
      
 178 
     | 
    
         
            +
                  trap :HUP do
         
     | 
| 
      
 179 
     | 
    
         
            +
                    $log.debug "fluentd supervisor process get SIGHUP"
         
     | 
| 
      
 180 
     | 
    
         
            +
                    supervisor_sighup_handler
         
     | 
| 
      
 181 
     | 
    
         
            +
                  end
         
     | 
| 
      
 182 
     | 
    
         
            +
             
     | 
| 
      
 183 
     | 
    
         
            +
                  trap :USR1 do
         
     | 
| 
      
 184 
     | 
    
         
            +
                    $log.debug "fluentd supervisor process get SIGUSR1"
         
     | 
| 
      
 185 
     | 
    
         
            +
                    supervisor_sigusr1_handler
         
     | 
| 
      
 186 
     | 
    
         
            +
                  end
         
     | 
| 
      
 187 
     | 
    
         
            +
             
     | 
| 
      
 188 
     | 
    
         
            +
                  trap :USR2 do
         
     | 
| 
      
 189 
     | 
    
         
            +
                    $log.debug 'fluentd supervisor process got SIGUSR2'
         
     | 
| 
      
 190 
     | 
    
         
            +
                    supervisor_sigusr2_handler
         
     | 
| 
      
 191 
     | 
    
         
            +
                  end
         
     | 
| 
      
 192 
     | 
    
         
            +
                end
         
     | 
| 
      
 193 
     | 
    
         
            +
             
     | 
| 
      
 194 
     | 
    
         
            +
                if Fluent.windows?
         
     | 
| 
      
 195 
     | 
    
         
            +
                  # Override some methods of ServerEngine::MultiSpawnWorker
         
     | 
| 
      
 196 
     | 
    
         
            +
                  # Since Fluentd's Supervisor doesn't use ServerEngine's HUP, USR1 and USR2
         
     | 
| 
      
 197 
     | 
    
         
            +
                  # handlers (see install_supervisor_signal_handlers), they should be
         
     | 
| 
      
 198 
     | 
    
         
            +
                  # disabled also on Windows, just send commands to workers instead.
         
     | 
| 
      
 199 
     | 
    
         
            +
                  def restart(graceful)
         
     | 
| 
      
 200 
     | 
    
         
            +
                    @monitors.each do |m|
         
     | 
| 
      
 201 
     | 
    
         
            +
                      m.send_command(graceful ? "GRACEFUL_RESTART\n" : "IMMEDIATE_RESTART\n")
         
     | 
| 
      
 202 
     | 
    
         
            +
                    end
         
     | 
| 
      
 203 
     | 
    
         
            +
                  end
         
     | 
| 
      
 204 
     | 
    
         
            +
             
     | 
| 
      
 205 
     | 
    
         
            +
                  def reload
         
     | 
| 
      
 206 
     | 
    
         
            +
                    @monitors.each do |m|
         
     | 
| 
      
 207 
     | 
    
         
            +
                      m.send_command("RELOAD\n")
         
     | 
| 
      
 208 
     | 
    
         
            +
                    end
         
     | 
| 
      
 209 
     | 
    
         
            +
                  end
         
     | 
| 
      
 210 
     | 
    
         
            +
                end
         
     | 
| 
      
 211 
     | 
    
         
            +
             
     | 
| 
      
 212 
     | 
    
         
            +
                def install_windows_event_handler
         
     | 
| 
      
 213 
     | 
    
         
            +
                  return unless Fluent.windows?
         
     | 
| 
      
 214 
     | 
    
         
            +
             
     | 
| 
      
 215 
     | 
    
         
            +
                  @pid_signame = "fluentd_#{Process.pid}"
         
     | 
| 
      
 216 
     | 
    
         
            +
                  @signame = config[:signame]
         
     | 
| 
      
 217 
     | 
    
         
            +
             
     | 
| 
      
 218 
     | 
    
         
            +
                  Thread.new do
         
     | 
| 
      
 219 
     | 
    
         
            +
                    ipc = Win32::Ipc.new(nil)
         
     | 
| 
      
 220 
     | 
    
         
            +
                    events = [
         
     | 
| 
      
 221 
     | 
    
         
            +
                      {win32_event: Win32::Event.new("#{@pid_signame}_STOP_EVENT_THREAD"), action: :stop_event_thread},
         
     | 
| 
      
 222 
     | 
    
         
            +
                      {win32_event: Win32::Event.new("#{@pid_signame}"), action: :stop},
         
     | 
| 
      
 223 
     | 
    
         
            +
                      {win32_event: Win32::Event.new("#{@pid_signame}_HUP"), action: :hup},
         
     | 
| 
      
 224 
     | 
    
         
            +
                      {win32_event: Win32::Event.new("#{@pid_signame}_USR1"), action: :usr1},
         
     | 
| 
      
 225 
     | 
    
         
            +
                      {win32_event: Win32::Event.new("#{@pid_signame}_USR2"), action: :usr2},
         
     | 
| 
      
 226 
     | 
    
         
            +
                      {win32_event: Win32::Event.new("#{@pid_signame}_CONT"), action: :cont},
         
     | 
| 
      
 227 
     | 
    
         
            +
                    ]
         
     | 
| 
      
 228 
     | 
    
         
            +
                    if @signame
         
     | 
| 
      
 229 
     | 
    
         
            +
                      signame_events = [
         
     | 
| 
      
 230 
     | 
    
         
            +
                        {win32_event: Win32::Event.new("#{@signame}"), action: :stop},
         
     | 
| 
      
 231 
     | 
    
         
            +
                        {win32_event: Win32::Event.new("#{@signame}_HUP"), action: :hup},
         
     | 
| 
      
 232 
     | 
    
         
            +
                        {win32_event: Win32::Event.new("#{@signame}_USR1"), action: :usr1},
         
     | 
| 
      
 233 
     | 
    
         
            +
                        {win32_event: Win32::Event.new("#{@signame}_USR2"), action: :usr2},
         
     | 
| 
      
 234 
     | 
    
         
            +
                        {win32_event: Win32::Event.new("#{@signame}_CONT"), action: :cont},
         
     | 
| 
      
 235 
     | 
    
         
            +
                      ]
         
     | 
| 
      
 236 
     | 
    
         
            +
                      events.concat(signame_events)
         
     | 
| 
      
 237 
     | 
    
         
            +
                    end
         
     | 
| 
      
 238 
     | 
    
         
            +
                    begin
         
     | 
| 
      
 239 
     | 
    
         
            +
                      loop do
         
     | 
| 
      
 240 
     | 
    
         
            +
                        infinite = 0xFFFFFFFF
         
     | 
| 
      
 241 
     | 
    
         
            +
                        ipc_idx = ipc.wait_any(events.map {|e| e[:win32_event]}, infinite)
         
     | 
| 
      
 242 
     | 
    
         
            +
                        event_idx = ipc_idx - 1
         
     | 
| 
      
 243 
     | 
    
         
            +
             
     | 
| 
      
 244 
     | 
    
         
            +
                        if event_idx >= 0 && event_idx < events.length
         
     | 
| 
      
 245 
     | 
    
         
            +
                          $log.debug("Got Win32 event \"#{events[event_idx][:win32_event].name}\"")
         
     | 
| 
      
 246 
     | 
    
         
            +
                        else
         
     | 
| 
      
 247 
     | 
    
         
            +
                          $log.warn("Unexpected return value of Win32::Ipc#wait_any: #{ipc_idx}")
         
     | 
| 
      
 248 
     | 
    
         
            +
                        end
         
     | 
| 
      
 249 
     | 
    
         
            +
                        case events[event_idx][:action]
         
     | 
| 
      
 250 
     | 
    
         
            +
                        when :stop
         
     | 
| 
      
 251 
     | 
    
         
            +
                          stop(true)
         
     | 
| 
      
 252 
     | 
    
         
            +
                        when :hup
         
     | 
| 
      
 253 
     | 
    
         
            +
                          supervisor_sighup_handler
         
     | 
| 
      
 254 
     | 
    
         
            +
                        when :usr1
         
     | 
| 
      
 255 
     | 
    
         
            +
                          supervisor_sigusr1_handler
         
     | 
| 
      
 256 
     | 
    
         
            +
                        when :usr2
         
     | 
| 
      
 257 
     | 
    
         
            +
                          supervisor_sigusr2_handler
         
     | 
| 
      
 258 
     | 
    
         
            +
                        when :cont
         
     | 
| 
      
 259 
     | 
    
         
            +
                          supervisor_dump_handler_for_windows
         
     | 
| 
      
 260 
     | 
    
         
            +
                        when :stop_event_thread
         
     | 
| 
      
 261 
     | 
    
         
            +
                          break
         
     | 
| 
      
 262 
     | 
    
         
            +
                        end
         
     | 
| 
      
 263 
     | 
    
         
            +
                      end
         
     | 
| 
      
 264 
     | 
    
         
            +
                    ensure
         
     | 
| 
      
 265 
     | 
    
         
            +
                      events.each { |event| event[:win32_event].close }
         
     | 
| 
      
 266 
     | 
    
         
            +
                    end
         
     | 
| 
      
 267 
     | 
    
         
            +
                  end
         
     | 
| 
      
 268 
     | 
    
         
            +
                end
         
     | 
| 
      
 269 
     | 
    
         
            +
             
     | 
| 
      
 270 
     | 
    
         
            +
                def stop_windows_event_thread
         
     | 
| 
      
 271 
     | 
    
         
            +
                  if Fluent.windows?
         
     | 
| 
      
 272 
     | 
    
         
            +
                    ev = Win32::Event.open("#{@pid_signame}_STOP_EVENT_THREAD")
         
     | 
| 
      
 273 
     | 
    
         
            +
                    ev.set
         
     | 
| 
      
 274 
     | 
    
         
            +
                    ev.close
         
     | 
| 
      
 275 
     | 
    
         
            +
                  end
         
     | 
| 
      
 276 
     | 
    
         
            +
                end
         
     | 
| 
      
 277 
     | 
    
         
            +
             
     | 
| 
      
 278 
     | 
    
         
            +
                def supervisor_sighup_handler
         
     | 
| 
      
 279 
     | 
    
         
            +
                  kill_worker
         
     | 
| 
      
 280 
     | 
    
         
            +
                end
         
     | 
| 
      
 281 
     | 
    
         
            +
             
     | 
| 
      
 282 
     | 
    
         
            +
                def supervisor_sigusr1_handler
         
     | 
| 
      
 283 
     | 
    
         
            +
                  reopen_log
         
     | 
| 
      
 284 
     | 
    
         
            +
                  send_signal_to_workers(:USR1)
         
     | 
| 
      
 285 
     | 
    
         
            +
                end
         
     | 
| 
      
 286 
     | 
    
         
            +
             
     | 
| 
      
 287 
     | 
    
         
            +
                def supervisor_sigusr2_handler
         
     | 
| 
      
 288 
     | 
    
         
            +
                  conf = nil
         
     | 
| 
      
 289 
     | 
    
         
            +
                  t = Thread.new do
         
     | 
| 
      
 290 
     | 
    
         
            +
                    $log.info 'Reloading new config'
         
     | 
| 
      
 291 
     | 
    
         
            +
             
     | 
| 
      
 292 
     | 
    
         
            +
                    # Validate that loading config is valid at first
         
     | 
| 
      
 293 
     | 
    
         
            +
                    conf = Fluent::Config.build(
         
     | 
| 
      
 294 
     | 
    
         
            +
                      config_path: config[:config_path],
         
     | 
| 
      
 295 
     | 
    
         
            +
                      encoding: config[:conf_encoding],
         
     | 
| 
      
 296 
     | 
    
         
            +
                      additional_config: config[:inline_config],
         
     | 
| 
      
 297 
     | 
    
         
            +
                      use_v1_config: config[:use_v1_config],
         
     | 
| 
      
 298 
     | 
    
         
            +
                    )
         
     | 
| 
      
 299 
     | 
    
         
            +
             
     | 
| 
      
 300 
     | 
    
         
            +
                    Fluent::VariableStore.try_to_reset do
         
     | 
| 
      
 301 
     | 
    
         
            +
                      Fluent::Engine.reload_config(conf, supervisor: true)
         
     | 
| 
      
 302 
     | 
    
         
            +
                    end
         
     | 
| 
      
 303 
     | 
    
         
            +
                  end
         
     | 
| 
      
 304 
     | 
    
         
            +
             
     | 
| 
      
 305 
     | 
    
         
            +
                  t.report_on_exception = false # Error is handled by myself
         
     | 
| 
      
 306 
     | 
    
         
            +
                  t.join
         
     | 
| 
      
 307 
     | 
    
         
            +
             
     | 
| 
      
 308 
     | 
    
         
            +
                  reopen_log
         
     | 
| 
      
 309 
     | 
    
         
            +
                  send_signal_to_workers(:USR2)
         
     | 
| 
      
 310 
     | 
    
         
            +
                  @fluentd_conf = conf.to_s
         
     | 
| 
      
 311 
     | 
    
         
            +
                rescue => e
         
     | 
| 
      
 312 
     | 
    
         
            +
                  $log.error "Failed to reload config file: #{e}"
         
     | 
| 
      
 313 
     | 
    
         
            +
                end
         
     | 
| 
      
 314 
     | 
    
         
            +
             
     | 
| 
      
 315 
     | 
    
         
            +
                def supervisor_dump_handler_for_windows
         
     | 
| 
      
 316 
     | 
    
         
            +
                  # As for UNIX-like, SIGCONT signal to each process makes the process output its dump-file,
         
     | 
| 
      
 317 
     | 
    
         
            +
                  # and it is implemented before the implementation of the function for Windows.
         
     | 
| 
      
 318 
     | 
    
         
            +
                  # It is possible to trap SIGCONT and handle it here also on UNIX-like,
         
     | 
| 
      
 319 
     | 
    
         
            +
                  # but for backward compatibility, this handler is currently for a Windows-only.
         
     | 
| 
      
 320 
     | 
    
         
            +
                  raise "[BUG] This function is for Windows ONLY." unless Fluent.windows?
         
     | 
| 
      
 321 
     | 
    
         
            +
             
     | 
| 
      
 322 
     | 
    
         
            +
                  Thread.new do
         
     | 
| 
      
 323 
     | 
    
         
            +
                    begin
         
     | 
| 
      
 324 
     | 
    
         
            +
                      FluentSigdump.dump_windows
         
     | 
| 
      
 325 
     | 
    
         
            +
                    rescue => e
         
     | 
| 
      
 326 
     | 
    
         
            +
                      $log.error "failed to dump: #{e}"
         
     | 
| 
      
 327 
     | 
    
         
            +
                    end
         
     | 
| 
      
 328 
     | 
    
         
            +
                  end
         
     | 
| 
      
 329 
     | 
    
         
            +
             
     | 
| 
      
 330 
     | 
    
         
            +
                  send_signal_to_workers(:CONT)
         
     | 
| 
      
 331 
     | 
    
         
            +
                rescue => e
         
     | 
| 
      
 332 
     | 
    
         
            +
                  $log.error "failed to dump: #{e}"
         
     | 
| 
      
 333 
     | 
    
         
            +
                end
         
     | 
| 
      
 334 
     | 
    
         
            +
             
     | 
| 
      
 335 
     | 
    
         
            +
                def kill_worker
         
     | 
| 
      
 336 
     | 
    
         
            +
                  if config[:worker_pid]
         
     | 
| 
      
 337 
     | 
    
         
            +
                    pids = config[:worker_pid].clone
         
     | 
| 
      
 338 
     | 
    
         
            +
                    config[:worker_pid].clear
         
     | 
| 
      
 339 
     | 
    
         
            +
                    pids.each_value do |pid|
         
     | 
| 
      
 340 
     | 
    
         
            +
                      if Fluent.windows?
         
     | 
| 
      
 341 
     | 
    
         
            +
                        Process.kill :KILL, pid
         
     | 
| 
      
 342 
     | 
    
         
            +
                      else
         
     | 
| 
      
 343 
     | 
    
         
            +
                        Process.kill :TERM, pid
         
     | 
| 
      
 344 
     | 
    
         
            +
                      end
         
     | 
| 
      
 345 
     | 
    
         
            +
                    end
         
     | 
| 
      
 346 
     | 
    
         
            +
                  end
         
     | 
| 
      
 347 
     | 
    
         
            +
                end
         
     | 
| 
      
 348 
     | 
    
         
            +
             
     | 
| 
      
 349 
     | 
    
         
            +
                def supervisor_dump_config_handler
         
     | 
| 
      
 350 
     | 
    
         
            +
                  $log.info @fluentd_conf
         
     | 
| 
      
 351 
     | 
    
         
            +
                end
         
     | 
| 
      
 352 
     | 
    
         
            +
             
     | 
| 
      
 353 
     | 
    
         
            +
                def supervisor_get_dump_config_handler
         
     | 
| 
      
 354 
     | 
    
         
            +
                  { conf: @fluentd_conf }
         
     | 
| 
      
 355 
     | 
    
         
            +
                end
         
     | 
| 
      
 356 
     | 
    
         
            +
             
     | 
| 
      
 357 
     | 
    
         
            +
                def dump
         
     | 
| 
      
 358 
     | 
    
         
            +
                  super unless @stop
         
     | 
| 
      
 359 
     | 
    
         
            +
                end
         
     | 
| 
      
 360 
     | 
    
         
            +
             
     | 
| 
      
 361 
     | 
    
         
            +
                private
         
     | 
| 
      
 362 
     | 
    
         
            +
             
     | 
| 
      
 363 
     | 
    
         
            +
                def reopen_log
         
     | 
| 
      
 364 
     | 
    
         
            +
                  if $log
         
     | 
| 
      
 365 
     | 
    
         
            +
                    # Creating new thread due to mutex can't lock
         
     | 
| 
      
 366 
     | 
    
         
            +
                    # in main thread during trap context
         
     | 
| 
      
 367 
     | 
    
         
            +
                    Thread.new do
         
     | 
| 
      
 368 
     | 
    
         
            +
                      $log.reopen!
         
     | 
| 
      
 369 
     | 
    
         
            +
                    end
         
     | 
| 
      
 370 
     | 
    
         
            +
                  end
         
     | 
| 
      
 371 
     | 
    
         
            +
                end
         
     | 
| 
      
 372 
     | 
    
         
            +
             
     | 
| 
      
 373 
     | 
    
         
            +
                def send_signal_to_workers(signal)
         
     | 
| 
      
 374 
     | 
    
         
            +
                  return unless config[:worker_pid]
         
     | 
| 
      
 375 
     | 
    
         
            +
             
     | 
| 
      
 376 
     | 
    
         
            +
                  if Fluent.windows?
         
     | 
| 
      
 377 
     | 
    
         
            +
                    send_command_to_workers(signal)
         
     | 
| 
      
 378 
     | 
    
         
            +
                  else
         
     | 
| 
      
 379 
     | 
    
         
            +
                    config[:worker_pid].each_value do |pid|
         
     | 
| 
      
 380 
     | 
    
         
            +
                      # don't rescue Errno::ESRCH here (invalid status)
         
     | 
| 
      
 381 
     | 
    
         
            +
                      Process.kill(signal, pid)
         
     | 
| 
      
 382 
     | 
    
         
            +
                    end
         
     | 
| 
      
 383 
     | 
    
         
            +
                  end
         
     | 
| 
      
 384 
     | 
    
         
            +
                end
         
     | 
| 
      
 385 
     | 
    
         
            +
             
     | 
| 
      
 386 
     | 
    
         
            +
                def send_command_to_workers(signal)
         
     | 
| 
      
 387 
     | 
    
         
            +
                  # Use SeverEngine's CommandSender on Windows
         
     | 
| 
      
 388 
     | 
    
         
            +
                  case signal
         
     | 
| 
      
 389 
     | 
    
         
            +
                  when :HUP
         
     | 
| 
      
 390 
     | 
    
         
            +
                    restart(false)
         
     | 
| 
      
 391 
     | 
    
         
            +
                  when :USR1
         
     | 
| 
      
 392 
     | 
    
         
            +
                    restart(true)
         
     | 
| 
      
 393 
     | 
    
         
            +
                  when :USR2
         
     | 
| 
      
 394 
     | 
    
         
            +
                    reload
         
     | 
| 
      
 395 
     | 
    
         
            +
                  when :CONT
         
     | 
| 
      
 396 
     | 
    
         
            +
                    dump_all_windows_workers
         
     | 
| 
      
 397 
     | 
    
         
            +
                  end
         
     | 
| 
      
 398 
     | 
    
         
            +
                end
         
     | 
| 
      
 399 
     | 
    
         
            +
             
     | 
| 
      
 400 
     | 
    
         
            +
                def dump_all_windows_workers
         
     | 
| 
      
 401 
     | 
    
         
            +
                  @monitors.each do |m|
         
     | 
| 
      
 402 
     | 
    
         
            +
                    m.send_command("DUMP\n")
         
     | 
| 
      
 403 
     | 
    
         
            +
                  end
         
     | 
| 
      
 404 
     | 
    
         
            +
                end
         
     | 
| 
      
 405 
     | 
    
         
            +
              end
         
     | 
| 
      
 406 
     | 
    
         
            +
             
     | 
| 
      
 407 
     | 
    
         
            +
              module WorkerModule
         
     | 
| 
      
 408 
     | 
    
         
            +
                def spawn(process_manager)
         
     | 
| 
      
 409 
     | 
    
         
            +
                  main_cmd = config[:main_cmd]
         
     | 
| 
      
 410 
     | 
    
         
            +
                  env = {
         
     | 
| 
      
 411 
     | 
    
         
            +
                    'SERVERENGINE_WORKER_ID' => @worker_id.to_i.to_s,
         
     | 
| 
      
 412 
     | 
    
         
            +
                  }
         
     | 
| 
      
 413 
     | 
    
         
            +
                  @pm = process_manager.spawn(env, *main_cmd)
         
     | 
| 
      
 414 
     | 
    
         
            +
                end
         
     | 
| 
      
 415 
     | 
    
         
            +
             
     | 
| 
      
 416 
     | 
    
         
            +
                def after_start
         
     | 
| 
      
 417 
     | 
    
         
            +
                  (config[:worker_pid] ||= {})[@worker_id] = @pm.pid
         
     | 
| 
      
 418 
     | 
    
         
            +
                end
         
     | 
| 
      
 419 
     | 
    
         
            +
             
     | 
| 
      
 420 
     | 
    
         
            +
                def dump
         
     | 
| 
      
 421 
     | 
    
         
            +
                  super unless @stop
         
     | 
| 
      
 422 
     | 
    
         
            +
                end
         
     | 
| 
      
 423 
     | 
    
         
            +
              end
         
     | 
| 
      
 424 
     | 
    
         
            +
             
     | 
| 
      
 425 
     | 
    
         
            +
              class Supervisor
         
     | 
| 
      
 426 
     | 
    
         
            +
                def self.serverengine_config(params = {})
         
     | 
| 
      
 427 
     | 
    
         
            +
                  # ServerEngine's "daemonize" option is boolean, and path of pid file is brought by "pid_path"
         
     | 
| 
      
 428 
     | 
    
         
            +
                  pid_path = params['daemonize']
         
     | 
| 
      
 429 
     | 
    
         
            +
                  daemonize = !!params['daemonize']
         
     | 
| 
      
 430 
     | 
    
         
            +
             
     | 
| 
      
 431 
     | 
    
         
            +
                  se_config = {
         
     | 
| 
      
 432 
     | 
    
         
            +
                    worker_type: 'spawn',
         
     | 
| 
      
 433 
     | 
    
         
            +
                    workers: params['workers'],
         
     | 
| 
      
 434 
     | 
    
         
            +
                    log_stdin: false,
         
     | 
| 
      
 435 
     | 
    
         
            +
                    log_stdout: false,
         
     | 
| 
      
 436 
     | 
    
         
            +
                    log_stderr: false,
         
     | 
| 
      
 437 
     | 
    
         
            +
                    enable_heartbeat: true,
         
     | 
| 
      
 438 
     | 
    
         
            +
                    auto_heartbeat: false,
         
     | 
| 
      
 439 
     | 
    
         
            +
                    unrecoverable_exit_codes: [2],
         
     | 
| 
      
 440 
     | 
    
         
            +
                    stop_immediately_at_unrecoverable_exit: true,
         
     | 
| 
      
 441 
     | 
    
         
            +
                    root_dir: params['root_dir'],
         
     | 
| 
      
 442 
     | 
    
         
            +
                    logger: $log,
         
     | 
| 
      
 443 
     | 
    
         
            +
                    log: $log.out,
         
     | 
| 
      
 444 
     | 
    
         
            +
                    log_level: params['log_level'],
         
     | 
| 
      
 445 
     | 
    
         
            +
                    chuser: params['chuser'],
         
     | 
| 
      
 446 
     | 
    
         
            +
                    chgroup: params['chgroup'],
         
     | 
| 
      
 447 
     | 
    
         
            +
                    chumask: params['chumask'],
         
     | 
| 
      
 448 
     | 
    
         
            +
                    daemonize: daemonize,
         
     | 
| 
      
 449 
     | 
    
         
            +
                    rpc_endpoint: params['rpc_endpoint'],
         
     | 
| 
      
 450 
     | 
    
         
            +
                    counter_server: params['counter_server'],
         
     | 
| 
      
 451 
     | 
    
         
            +
                    enable_get_dump: params['enable_get_dump'],
         
     | 
| 
      
 452 
     | 
    
         
            +
                    windows_daemon_cmdline: [ServerEngine.ruby_bin_path,
         
     | 
| 
      
 453 
     | 
    
         
            +
                                             File.join(File.dirname(__FILE__), 'daemon.rb'),
         
     | 
| 
      
 454 
     | 
    
         
            +
                                             ServerModule.name,
         
     | 
| 
      
 455 
     | 
    
         
            +
                                             WorkerModule.name,
         
     | 
| 
      
 456 
     | 
    
         
            +
                                             JSON.dump(params)],
         
     | 
| 
      
 457 
     | 
    
         
            +
                    command_sender: Fluent.windows? ? "pipe" : "signal",
         
     | 
| 
      
 458 
     | 
    
         
            +
                    config_path: params['fluentd_conf_path'],
         
     | 
| 
      
 459 
     | 
    
         
            +
                    fluentd_conf: params['fluentd_conf'],
         
     | 
| 
      
 460 
     | 
    
         
            +
                    conf_encoding: params['conf_encoding'],
         
     | 
| 
      
 461 
     | 
    
         
            +
                    inline_config: params['inline_config'],
         
     | 
| 
      
 462 
     | 
    
         
            +
                    main_cmd: params['main_cmd'],
         
     | 
| 
      
 463 
     | 
    
         
            +
                    signame: params['signame'],
         
     | 
| 
      
 464 
     | 
    
         
            +
                    disable_shared_socket: params['disable_shared_socket'],
         
     | 
| 
      
 465 
     | 
    
         
            +
                    restart_worker_interval: params['restart_worker_interval'],
         
     | 
| 
      
 466 
     | 
    
         
            +
                  }
         
     | 
| 
      
 467 
     | 
    
         
            +
                  se_config[:pid_path] = pid_path if daemonize
         
     | 
| 
      
 468 
     | 
    
         
            +
             
     | 
| 
      
 469 
     | 
    
         
            +
                  se_config
         
     | 
| 
      
 470 
     | 
    
         
            +
                end
         
     | 
| 
      
 471 
     | 
    
         
            +
             
     | 
| 
      
 472 
     | 
    
         
            +
                def self.default_options
         
     | 
| 
      
 473 
     | 
    
         
            +
                  {
         
     | 
| 
      
 474 
     | 
    
         
            +
                    config_path: Fluent::DEFAULT_CONFIG_PATH,
         
     | 
| 
      
 475 
     | 
    
         
            +
                    plugin_dirs: [Fluent::DEFAULT_PLUGIN_DIR],
         
     | 
| 
      
 476 
     | 
    
         
            +
                    log_level: Fluent::Log::LEVEL_INFO,
         
     | 
| 
      
 477 
     | 
    
         
            +
                    log_path: nil,
         
     | 
| 
      
 478 
     | 
    
         
            +
                    daemonize: nil,
         
     | 
| 
      
 479 
     | 
    
         
            +
                    libs: [],
         
     | 
| 
      
 480 
     | 
    
         
            +
                    setup_path: nil,
         
     | 
| 
      
 481 
     | 
    
         
            +
                    chuser: nil,
         
     | 
| 
      
 482 
     | 
    
         
            +
                    chgroup: nil,
         
     | 
| 
      
 483 
     | 
    
         
            +
                    chumask: "0",
         
     | 
| 
      
 484 
     | 
    
         
            +
                    root_dir: nil,
         
     | 
| 
      
 485 
     | 
    
         
            +
                    suppress_interval: 0,
         
     | 
| 
      
 486 
     | 
    
         
            +
                    suppress_repeated_stacktrace: true,
         
     | 
| 
      
 487 
     | 
    
         
            +
                    ignore_repeated_log_interval: nil,
         
     | 
| 
      
 488 
     | 
    
         
            +
                    without_source: nil,
         
     | 
| 
      
 489 
     | 
    
         
            +
                    enable_input_metrics: nil,
         
     | 
| 
      
 490 
     | 
    
         
            +
                    enable_size_metrics: nil,
         
     | 
| 
      
 491 
     | 
    
         
            +
                    use_v1_config: true,
         
     | 
| 
      
 492 
     | 
    
         
            +
                    strict_config_value: nil,
         
     | 
| 
      
 493 
     | 
    
         
            +
                    supervise: true,
         
     | 
| 
      
 494 
     | 
    
         
            +
                    standalone_worker: false,
         
     | 
| 
      
 495 
     | 
    
         
            +
                    signame: nil,
         
     | 
| 
      
 496 
     | 
    
         
            +
                    conf_encoding: 'utf-8',
         
     | 
| 
      
 497 
     | 
    
         
            +
                    disable_shared_socket: nil,
         
     | 
| 
      
 498 
     | 
    
         
            +
                    config_file_type: :guess,
         
     | 
| 
      
 499 
     | 
    
         
            +
                  }
         
     | 
| 
      
 500 
     | 
    
         
            +
                end
         
     | 
| 
      
 501 
     | 
    
         
            +
             
     | 
| 
      
 502 
     | 
    
         
            +
                def self.cleanup_resources
         
     | 
| 
      
 503 
     | 
    
         
            +
                  unless Fluent.windows?
         
     | 
| 
      
 504 
     | 
    
         
            +
                    if ENV.has_key?('SERVERENGINE_SOCKETMANAGER_PATH')
         
     | 
| 
      
 505 
     | 
    
         
            +
                      FileUtils.rm_f(ENV['SERVERENGINE_SOCKETMANAGER_PATH'])
         
     | 
| 
      
 506 
     | 
    
         
            +
                    end
         
     | 
| 
      
 507 
     | 
    
         
            +
                  end
         
     | 
| 
      
 508 
     | 
    
         
            +
                end
         
     | 
| 
      
 509 
     | 
    
         
            +
             
     | 
| 
      
 510 
     | 
    
         
            +
                def initialize(cl_opt)
         
     | 
| 
      
 511 
     | 
    
         
            +
                  @cl_opt = cl_opt
         
     | 
| 
      
 512 
     | 
    
         
            +
                  opt = self.class.default_options.merge(cl_opt)
         
     | 
| 
      
 513 
     | 
    
         
            +
             
     | 
| 
      
 514 
     | 
    
         
            +
                  @config_file_type = opt[:config_file_type]
         
     | 
| 
      
 515 
     | 
    
         
            +
                  @daemonize = opt[:daemonize]
         
     | 
| 
      
 516 
     | 
    
         
            +
                  @standalone_worker= opt[:standalone_worker]
         
     | 
| 
      
 517 
     | 
    
         
            +
                  @config_path = opt[:config_path]
         
     | 
| 
      
 518 
     | 
    
         
            +
                  @inline_config = opt[:inline_config]
         
     | 
| 
      
 519 
     | 
    
         
            +
                  @use_v1_config = opt[:use_v1_config]
         
     | 
| 
      
 520 
     | 
    
         
            +
                  @conf_encoding = opt[:conf_encoding]
         
     | 
| 
      
 521 
     | 
    
         
            +
                  @log_path = opt[:log_path]
         
     | 
| 
      
 522 
     | 
    
         
            +
                  @show_plugin_config = opt[:show_plugin_config]
         
     | 
| 
      
 523 
     | 
    
         
            +
                  @libs = opt[:libs]
         
     | 
| 
      
 524 
     | 
    
         
            +
                  @plugin_dirs = opt[:plugin_dirs]
         
     | 
| 
      
 525 
     | 
    
         
            +
                  @chgroup = opt[:chgroup]
         
     | 
| 
      
 526 
     | 
    
         
            +
                  @chuser = opt[:chuser]
         
     | 
| 
      
 527 
     | 
    
         
            +
                  @chumask = opt[:chumask]
         
     | 
| 
      
 528 
     | 
    
         
            +
                  @signame = opt[:signame]
         
     | 
| 
      
 529 
     | 
    
         
            +
             
     | 
| 
      
 530 
     | 
    
         
            +
                  # TODO: `@log_rotate_age` and `@log_rotate_size` should be removed
         
     | 
| 
      
 531 
     | 
    
         
            +
                  # since it should be merged with SystemConfig in `build_system_config()`.
         
     | 
| 
      
 532 
     | 
    
         
            +
                  # We should always use `system_config.log.rotate_age` and `system_config.log.rotate_size`.
         
     | 
| 
      
 533 
     | 
    
         
            +
                  # However, currently, there is a bug that `system_config.log` parameters
         
     | 
| 
      
 534 
     | 
    
         
            +
                  # are not in `Fluent::SystemConfig::SYSTEM_CONFIG_PARAMETERS`, and these
         
     | 
| 
      
 535 
     | 
    
         
            +
                  # parameters are not merged in `build_system_config()`.
         
     | 
| 
      
 536 
     | 
    
         
            +
                  # Until we fix the bug of `Fluent::SystemConfig`, we need to use these instance variables.
         
     | 
| 
      
 537 
     | 
    
         
            +
                  @log_rotate_age = opt[:log_rotate_age]
         
     | 
| 
      
 538 
     | 
    
         
            +
                  @log_rotate_size = opt[:log_rotate_size]
         
     | 
| 
      
 539 
     | 
    
         
            +
             
     | 
| 
      
 540 
     | 
    
         
            +
                  @finished = false
         
     | 
| 
      
 541 
     | 
    
         
            +
                end
         
     | 
| 
      
 542 
     | 
    
         
            +
             
     | 
| 
      
 543 
     | 
    
         
            +
                def run_supervisor(dry_run: false)
         
     | 
| 
      
 544 
     | 
    
         
            +
                  if dry_run
         
     | 
| 
      
 545 
     | 
    
         
            +
                    $log.info "starting fluentd-#{Fluent::VERSION} as dry run mode", ruby: RUBY_VERSION
         
     | 
| 
      
 546 
     | 
    
         
            +
                  end
         
     | 
| 
      
 547 
     | 
    
         
            +
             
     | 
| 
      
 548 
     | 
    
         
            +
                  if @system_config.workers < 1
         
     | 
| 
      
 549 
     | 
    
         
            +
                    raise Fluent::ConfigError, "invalid number of workers (must be > 0):#{@system_config.workers}"
         
     | 
| 
      
 550 
     | 
    
         
            +
                  end
         
     | 
| 
      
 551 
     | 
    
         
            +
             
     | 
| 
      
 552 
     | 
    
         
            +
                  root_dir = @system_config.root_dir
         
     | 
| 
      
 553 
     | 
    
         
            +
                  if root_dir
         
     | 
| 
      
 554 
     | 
    
         
            +
                    if File.exist?(root_dir)
         
     | 
| 
      
 555 
     | 
    
         
            +
                      unless Dir.exist?(root_dir)
         
     | 
| 
      
 556 
     | 
    
         
            +
                        raise Fluent::InvalidRootDirectory, "non directory entry exists:#{root_dir}"
         
     | 
| 
      
 557 
     | 
    
         
            +
                      end
         
     | 
| 
      
 558 
     | 
    
         
            +
                    else
         
     | 
| 
      
 559 
     | 
    
         
            +
                      begin
         
     | 
| 
      
 560 
     | 
    
         
            +
                        FileUtils.mkdir_p(root_dir, mode: @system_config.dir_permission || Fluent::DEFAULT_DIR_PERMISSION)
         
     | 
| 
      
 561 
     | 
    
         
            +
                      rescue => e
         
     | 
| 
      
 562 
     | 
    
         
            +
                        raise Fluent::InvalidRootDirectory, "failed to create root directory:#{root_dir}, #{e.inspect}"
         
     | 
| 
      
 563 
     | 
    
         
            +
                      end
         
     | 
| 
      
 564 
     | 
    
         
            +
                    end
         
     | 
| 
      
 565 
     | 
    
         
            +
                  end
         
     | 
| 
      
 566 
     | 
    
         
            +
             
     | 
| 
      
 567 
     | 
    
         
            +
                  begin
         
     | 
| 
      
 568 
     | 
    
         
            +
                    ServerEngine::Privilege.change(@chuser, @chgroup)
         
     | 
| 
      
 569 
     | 
    
         
            +
                    MessagePackFactory.init(enable_time_support: @system_config.enable_msgpack_time_support)
         
     | 
| 
      
 570 
     | 
    
         
            +
                    Fluent::Engine.init(@system_config, supervisor_mode: true)
         
     | 
| 
      
 571 
     | 
    
         
            +
                    Fluent::Engine.run_configure(@conf, dry_run: dry_run)
         
     | 
| 
      
 572 
     | 
    
         
            +
                  rescue Fluent::ConfigError => e
         
     | 
| 
      
 573 
     | 
    
         
            +
                    $log.error 'config error', file: @config_path, error: e
         
     | 
| 
      
 574 
     | 
    
         
            +
                    $log.debug_backtrace
         
     | 
| 
      
 575 
     | 
    
         
            +
                    exit!(1)
         
     | 
| 
      
 576 
     | 
    
         
            +
                  end
         
     | 
| 
      
 577 
     | 
    
         
            +
             
     | 
| 
      
 578 
     | 
    
         
            +
                  if dry_run
         
     | 
| 
      
 579 
     | 
    
         
            +
                    $log.info 'finished dry run mode'
         
     | 
| 
      
 580 
     | 
    
         
            +
                    exit 0
         
     | 
| 
      
 581 
     | 
    
         
            +
                  else
         
     | 
| 
      
 582 
     | 
    
         
            +
                    supervise
         
     | 
| 
      
 583 
     | 
    
         
            +
                  end
         
     | 
| 
      
 584 
     | 
    
         
            +
                end
         
     | 
| 
      
 585 
     | 
    
         
            +
             
     | 
| 
      
 586 
     | 
    
         
            +
                def options
         
     | 
| 
      
 587 
     | 
    
         
            +
                  {
         
     | 
| 
      
 588 
     | 
    
         
            +
                    'config_path' => @config_path,
         
     | 
| 
      
 589 
     | 
    
         
            +
                    'pid_file' => @daemonize,
         
     | 
| 
      
 590 
     | 
    
         
            +
                    'plugin_dirs' => @plugin_dirs,
         
     | 
| 
      
 591 
     | 
    
         
            +
                    'log_path' => @log_path,
         
     | 
| 
      
 592 
     | 
    
         
            +
                    'root_dir' => @system_config.root_dir,
         
     | 
| 
      
 593 
     | 
    
         
            +
                  }
         
     | 
| 
      
 594 
     | 
    
         
            +
                end
         
     | 
| 
      
 595 
     | 
    
         
            +
             
     | 
| 
      
 596 
     | 
    
         
            +
                def run_worker
         
     | 
| 
      
 597 
     | 
    
         
            +
                  Process.setproctitle("worker:#{@system_config.process_name}") if @process_name
         
     | 
| 
      
 598 
     | 
    
         
            +
             
     | 
| 
      
 599 
     | 
    
         
            +
                  if @standalone_worker && @system_config.workers != 1
         
     | 
| 
      
 600 
     | 
    
         
            +
                    raise Fluent::ConfigError, "invalid number of workers (must be 1 or unspecified) with --no-supervisor: #{@system_config.workers}"
         
     | 
| 
      
 601 
     | 
    
         
            +
                  end
         
     | 
| 
      
 602 
     | 
    
         
            +
             
     | 
| 
      
 603 
     | 
    
         
            +
                  install_main_process_signal_handlers
         
     | 
| 
      
 604 
     | 
    
         
            +
             
     | 
| 
      
 605 
     | 
    
         
            +
                  # This is the only log messsage for @standalone_worker
         
     | 
| 
      
 606 
     | 
    
         
            +
                  $log.info "starting fluentd-#{Fluent::VERSION} without supervision", pid: Process.pid, ruby: RUBY_VERSION if @standalone_worker
         
     | 
| 
      
 607 
     | 
    
         
            +
             
     | 
| 
      
 608 
     | 
    
         
            +
                  main_process do
         
     | 
| 
      
 609 
     | 
    
         
            +
                    create_socket_manager if @standalone_worker
         
     | 
| 
      
 610 
     | 
    
         
            +
                    if @standalone_worker
         
     | 
| 
      
 611 
     | 
    
         
            +
                      ServerEngine::Privilege.change(@chuser, @chgroup)
         
     | 
| 
      
 612 
     | 
    
         
            +
                      File.umask(@chumask.to_i(8))
         
     | 
| 
      
 613 
     | 
    
         
            +
                    end
         
     | 
| 
      
 614 
     | 
    
         
            +
                    MessagePackFactory.init(enable_time_support: @system_config.enable_msgpack_time_support)
         
     | 
| 
      
 615 
     | 
    
         
            +
                    Fluent::Engine.init(@system_config)
         
     | 
| 
      
 616 
     | 
    
         
            +
                    Fluent::Engine.run_configure(@conf)
         
     | 
| 
      
 617 
     | 
    
         
            +
                    Fluent::Engine.run
         
     | 
| 
      
 618 
     | 
    
         
            +
                    self.class.cleanup_resources if @standalone_worker
         
     | 
| 
      
 619 
     | 
    
         
            +
                    exit 0
         
     | 
| 
      
 620 
     | 
    
         
            +
                  end
         
     | 
| 
      
 621 
     | 
    
         
            +
                end
         
     | 
| 
      
 622 
     | 
    
         
            +
             
     | 
| 
      
 623 
     | 
    
         
            +
                def configure(supervisor: false)
         
     | 
| 
      
 624 
     | 
    
         
            +
                  setup_global_logger(supervisor: supervisor)
         
     | 
| 
      
 625 
     | 
    
         
            +
             
     | 
| 
      
 626 
     | 
    
         
            +
                  if @show_plugin_config
         
     | 
| 
      
 627 
     | 
    
         
            +
                    show_plugin_config
         
     | 
| 
      
 628 
     | 
    
         
            +
                  end
         
     | 
| 
      
 629 
     | 
    
         
            +
             
     | 
| 
      
 630 
     | 
    
         
            +
                  if @inline_config == '-'
         
     | 
| 
      
 631 
     | 
    
         
            +
                    $log.warn('the value "-" for `inline_config` is deprecated. See https://github.com/fluent/fluentd/issues/2711')
         
     | 
| 
      
 632 
     | 
    
         
            +
                    @inline_config = STDIN.read
         
     | 
| 
      
 633 
     | 
    
         
            +
                  end
         
     | 
| 
      
 634 
     | 
    
         
            +
                  @conf = Fluent::Config.build(
         
     | 
| 
      
 635 
     | 
    
         
            +
                    config_path: @config_path,
         
     | 
| 
      
 636 
     | 
    
         
            +
                    encoding: @conf_encoding,
         
     | 
| 
      
 637 
     | 
    
         
            +
                    additional_config: @inline_config,
         
     | 
| 
      
 638 
     | 
    
         
            +
                    use_v1_config: @use_v1_config,
         
     | 
| 
      
 639 
     | 
    
         
            +
                    type: @config_file_type,
         
     | 
| 
      
 640 
     | 
    
         
            +
                  )
         
     | 
| 
      
 641 
     | 
    
         
            +
                  @system_config = build_system_config(@conf)
         
     | 
| 
      
 642 
     | 
    
         
            +
             
     | 
| 
      
 643 
     | 
    
         
            +
                  $log.info :supervisor, 'parsing config file is succeeded', path: @config_path
         
     | 
| 
      
 644 
     | 
    
         
            +
             
     | 
| 
      
 645 
     | 
    
         
            +
                  @libs.each do |lib|
         
     | 
| 
      
 646 
     | 
    
         
            +
                    require lib
         
     | 
| 
      
 647 
     | 
    
         
            +
                  end
         
     | 
| 
      
 648 
     | 
    
         
            +
             
     | 
| 
      
 649 
     | 
    
         
            +
                  @plugin_dirs.each do |dir|
         
     | 
| 
      
 650 
     | 
    
         
            +
                    if Dir.exist?(dir)
         
     | 
| 
      
 651 
     | 
    
         
            +
                      dir = File.expand_path(dir)
         
     | 
| 
      
 652 
     | 
    
         
            +
                      Fluent::Plugin.add_plugin_dir(dir)
         
     | 
| 
      
 653 
     | 
    
         
            +
                    end
         
     | 
| 
      
 654 
     | 
    
         
            +
                  end
         
     | 
| 
      
 655 
     | 
    
         
            +
             
     | 
| 
      
 656 
     | 
    
         
            +
                  if supervisor
         
     | 
| 
      
 657 
     | 
    
         
            +
                    # plugins / configuration dumps
         
     | 
| 
      
 658 
     | 
    
         
            +
                    Gem::Specification.find_all.select { |x| x.name =~ /^fluent(d|-(plugin|mixin)-.*)$/ }.each do |spec|
         
     | 
| 
      
 659 
     | 
    
         
            +
                      $log.info("gem '#{spec.name}' version '#{spec.version}'")
         
     | 
| 
      
 660 
     | 
    
         
            +
                    end
         
     | 
| 
      
 661 
     | 
    
         
            +
                  end
         
     | 
| 
      
 662 
     | 
    
         
            +
                end
         
     | 
| 
      
 663 
     | 
    
         
            +
             
     | 
| 
      
 664 
     | 
    
         
            +
                private
         
     | 
| 
      
 665 
     | 
    
         
            +
             
     | 
| 
      
 666 
     | 
    
         
            +
                def setup_global_logger(supervisor: false)
         
     | 
| 
      
 667 
     | 
    
         
            +
                  if supervisor
         
     | 
| 
      
 668 
     | 
    
         
            +
                    worker_id = 0
         
     | 
| 
      
 669 
     | 
    
         
            +
                    process_type = :supervisor
         
     | 
| 
      
 670 
     | 
    
         
            +
                  else
         
     | 
| 
      
 671 
     | 
    
         
            +
                    worker_id = ENV['SERVERENGINE_WORKER_ID'].to_i
         
     | 
| 
      
 672 
     | 
    
         
            +
                    process_type = case
         
     | 
| 
      
 673 
     | 
    
         
            +
                                   when @standalone_worker then :standalone
         
     | 
| 
      
 674 
     | 
    
         
            +
                                   when worker_id == 0 then :worker0
         
     | 
| 
      
 675 
     | 
    
         
            +
                                   else :workers
         
     | 
| 
      
 676 
     | 
    
         
            +
                                   end
         
     | 
| 
      
 677 
     | 
    
         
            +
                  end
         
     | 
| 
      
 678 
     | 
    
         
            +
             
     | 
| 
      
 679 
     | 
    
         
            +
                  # Parse configuration immediately to initialize logger in early stage.
         
     | 
| 
      
 680 
     | 
    
         
            +
                  # Since we can't confirm the log messages in this parsing process,
         
     | 
| 
      
 681 
     | 
    
         
            +
                  # we must parse the config again after initializing logger.
         
     | 
| 
      
 682 
     | 
    
         
            +
                  conf = Fluent::Config.build(
         
     | 
| 
      
 683 
     | 
    
         
            +
                    config_path: @config_path,
         
     | 
| 
      
 684 
     | 
    
         
            +
                    encoding: @conf_encoding,
         
     | 
| 
      
 685 
     | 
    
         
            +
                    additional_config: @inline_config,
         
     | 
| 
      
 686 
     | 
    
         
            +
                    use_v1_config: @use_v1_config,
         
     | 
| 
      
 687 
     | 
    
         
            +
                    type: @config_file_type,
         
     | 
| 
      
 688 
     | 
    
         
            +
                  )
         
     | 
| 
      
 689 
     | 
    
         
            +
                  system_config = build_system_config(conf)
         
     | 
| 
      
 690 
     | 
    
         
            +
             
     | 
| 
      
 691 
     | 
    
         
            +
                  # TODO: we should remove this logic. This merging process should be done
         
     | 
| 
      
 692 
     | 
    
         
            +
                  # in `build_system_config()`.
         
     | 
| 
      
 693 
     | 
    
         
            +
                  @log_rotate_age ||= system_config.log.rotate_age
         
     | 
| 
      
 694 
     | 
    
         
            +
                  @log_rotate_size ||= system_config.log.rotate_size
         
     | 
| 
      
 695 
     | 
    
         
            +
             
     | 
| 
      
 696 
     | 
    
         
            +
                  rotate = @log_rotate_age || @log_rotate_size
         
     | 
| 
      
 697 
     | 
    
         
            +
                  actual_log_path = @log_path
         
     | 
| 
      
 698 
     | 
    
         
            +
             
     | 
| 
      
 699 
     | 
    
         
            +
                  # We need to prepare a unique path for each worker since Windows locks files.
         
     | 
| 
      
 700 
     | 
    
         
            +
                  if Fluent.windows? && rotate && @log_path && @log_path != "-"
         
     | 
| 
      
 701 
     | 
    
         
            +
                    actual_log_path = Fluent::Log.per_process_path(@log_path, process_type, worker_id)
         
     | 
| 
      
 702 
     | 
    
         
            +
                  end
         
     | 
| 
      
 703 
     | 
    
         
            +
             
     | 
| 
      
 704 
     | 
    
         
            +
                  if actual_log_path && actual_log_path != "-"
         
     | 
| 
      
 705 
     | 
    
         
            +
                    FileUtils.mkdir_p(File.dirname(actual_log_path)) unless File.exist?(actual_log_path)
         
     | 
| 
      
 706 
     | 
    
         
            +
                    if rotate
         
     | 
| 
      
 707 
     | 
    
         
            +
                      logdev = Fluent::LogDeviceIO.new(
         
     | 
| 
      
 708 
     | 
    
         
            +
                        actual_log_path,
         
     | 
| 
      
 709 
     | 
    
         
            +
                        shift_age: @log_rotate_age,
         
     | 
| 
      
 710 
     | 
    
         
            +
                        shift_size: @log_rotate_size,
         
     | 
| 
      
 711 
     | 
    
         
            +
                      )
         
     | 
| 
      
 712 
     | 
    
         
            +
                    else
         
     | 
| 
      
 713 
     | 
    
         
            +
                      logdev = File.open(actual_log_path, "a")
         
     | 
| 
      
 714 
     | 
    
         
            +
                    end
         
     | 
| 
      
 715 
     | 
    
         
            +
             
     | 
| 
      
 716 
     | 
    
         
            +
                    if @chuser || @chgroup
         
     | 
| 
      
 717 
     | 
    
         
            +
                      chuid = @chuser ? ServerEngine::Privilege.get_etc_passwd(@chuser).uid : nil
         
     | 
| 
      
 718 
     | 
    
         
            +
                      chgid = @chgroup ? ServerEngine::Privilege.get_etc_group(@chgroup).gid : nil
         
     | 
| 
      
 719 
     | 
    
         
            +
                      File.chown(chuid, chgid, actual_log_path)
         
     | 
| 
      
 720 
     | 
    
         
            +
                    end
         
     | 
| 
      
 721 
     | 
    
         
            +
             
     | 
| 
      
 722 
     | 
    
         
            +
                    if system_config.dir_permission
         
     | 
| 
      
 723 
     | 
    
         
            +
                      File.chmod(system_config.dir_permission || Fluent::DEFAULT_DIR_PERMISSION, File.dirname(actual_log_path))
         
     | 
| 
      
 724 
     | 
    
         
            +
                    end
         
     | 
| 
      
 725 
     | 
    
         
            +
                  else
         
     | 
| 
      
 726 
     | 
    
         
            +
                    logdev = STDOUT
         
     | 
| 
      
 727 
     | 
    
         
            +
                  end
         
     | 
| 
      
 728 
     | 
    
         
            +
             
     | 
| 
      
 729 
     | 
    
         
            +
                  $log = Fluent::Log.new(
         
     | 
| 
      
 730 
     | 
    
         
            +
                    # log_level: subtract 1 to match serverengine daemon logger side logging severity.
         
     | 
| 
      
 731 
     | 
    
         
            +
                    ServerEngine::DaemonLogger.new(logdev, log_level: system_config.log_level - 1),
         
     | 
| 
      
 732 
     | 
    
         
            +
                    path: actual_log_path,
         
     | 
| 
      
 733 
     | 
    
         
            +
                    process_type: process_type,
         
     | 
| 
      
 734 
     | 
    
         
            +
                    worker_id: worker_id,
         
     | 
| 
      
 735 
     | 
    
         
            +
                    format: system_config.log.format,
         
     | 
| 
      
 736 
     | 
    
         
            +
                    time_format: system_config.log.time_format,
         
     | 
| 
      
 737 
     | 
    
         
            +
                    suppress_repeated_stacktrace: system_config.suppress_repeated_stacktrace,
         
     | 
| 
      
 738 
     | 
    
         
            +
                    ignore_repeated_log_interval: system_config.ignore_repeated_log_interval,
         
     | 
| 
      
 739 
     | 
    
         
            +
                    ignore_same_log_interval: system_config.ignore_same_log_interval,
         
     | 
| 
      
 740 
     | 
    
         
            +
                  )
         
     | 
| 
      
 741 
     | 
    
         
            +
                  $log.enable_color(false) if actual_log_path
         
     | 
| 
      
 742 
     | 
    
         
            +
                  $log.enable_debug if system_config.log_level <= Fluent::Log::LEVEL_DEBUG
         
     | 
| 
      
 743 
     | 
    
         
            +
             
     | 
| 
      
 744 
     | 
    
         
            +
                  $log.info "init #{process_type} logger",
         
     | 
| 
      
 745 
     | 
    
         
            +
                            path: actual_log_path, 
         
     | 
| 
      
 746 
     | 
    
         
            +
                            rotate_age: @log_rotate_age,
         
     | 
| 
      
 747 
     | 
    
         
            +
                            rotate_size: @log_rotate_size
         
     | 
| 
      
 748 
     | 
    
         
            +
                end
         
     | 
| 
      
 749 
     | 
    
         
            +
             
     | 
| 
      
 750 
     | 
    
         
            +
                def create_socket_manager
         
     | 
| 
      
 751 
     | 
    
         
            +
                  server = ServerEngine::SocketManager::Server.open
         
     | 
| 
      
 752 
     | 
    
         
            +
                  ENV['SERVERENGINE_SOCKETMANAGER_PATH'] = server.path.to_s
         
     | 
| 
      
 753 
     | 
    
         
            +
                end
         
     | 
| 
      
 754 
     | 
    
         
            +
             
     | 
| 
      
 755 
     | 
    
         
            +
                def show_plugin_config
         
     | 
| 
      
 756 
     | 
    
         
            +
                  name, type = @show_plugin_config.split(":") # input:tail
         
     | 
| 
      
 757 
     | 
    
         
            +
                  $log.info "show_plugin_config option is deprecated. Use fluent-plugin-config-format --format=txt #{name} #{type}"
         
     | 
| 
      
 758 
     | 
    
         
            +
                  exit 0
         
     | 
| 
      
 759 
     | 
    
         
            +
                end
         
     | 
| 
      
 760 
     | 
    
         
            +
             
     | 
| 
      
 761 
     | 
    
         
            +
                def supervise
         
     | 
| 
      
 762 
     | 
    
         
            +
                  Process.setproctitle("supervisor:#{@system_config.process_name}") if @system_config.process_name
         
     | 
| 
      
 763 
     | 
    
         
            +
                  $log.info "starting fluentd-#{Fluent::VERSION}", pid: Process.pid, ruby: RUBY_VERSION
         
     | 
| 
      
 764 
     | 
    
         
            +
             
     | 
| 
      
 765 
     | 
    
         
            +
                  fluentd_spawn_cmd = build_spawn_command
         
     | 
| 
      
 766 
     | 
    
         
            +
                  $log.info "spawn command to main: ", cmdline: fluentd_spawn_cmd
         
     | 
| 
      
 767 
     | 
    
         
            +
             
     | 
| 
      
 768 
     | 
    
         
            +
                  params = {
         
     | 
| 
      
 769 
     | 
    
         
            +
                    'main_cmd' => fluentd_spawn_cmd,
         
     | 
| 
      
 770 
     | 
    
         
            +
                    'daemonize' => @daemonize,
         
     | 
| 
      
 771 
     | 
    
         
            +
                    'inline_config' => @inline_config,
         
     | 
| 
      
 772 
     | 
    
         
            +
                    'chuser' => @chuser,
         
     | 
| 
      
 773 
     | 
    
         
            +
                    'chgroup' => @chgroup,
         
     | 
| 
      
 774 
     | 
    
         
            +
                    'fluentd_conf_path' => @config_path,
         
     | 
| 
      
 775 
     | 
    
         
            +
                    'fluentd_conf' => @conf.to_s,
         
     | 
| 
      
 776 
     | 
    
         
            +
                    'use_v1_config' => @use_v1_config,
         
     | 
| 
      
 777 
     | 
    
         
            +
                    'conf_encoding' => @conf_encoding,
         
     | 
| 
      
 778 
     | 
    
         
            +
                    'signame' => @signame,
         
     | 
| 
      
 779 
     | 
    
         
            +
             
     | 
| 
      
 780 
     | 
    
         
            +
                    'workers' => @system_config.workers,
         
     | 
| 
      
 781 
     | 
    
         
            +
                    'root_dir' => @system_config.root_dir,
         
     | 
| 
      
 782 
     | 
    
         
            +
                    'log_level' => @system_config.log_level,
         
     | 
| 
      
 783 
     | 
    
         
            +
                    'rpc_endpoint' => @system_config.rpc_endpoint,
         
     | 
| 
      
 784 
     | 
    
         
            +
                    'enable_get_dump' => @system_config.enable_get_dump,
         
     | 
| 
      
 785 
     | 
    
         
            +
                    'counter_server' => @system_config.counter_server,
         
     | 
| 
      
 786 
     | 
    
         
            +
                    'disable_shared_socket' => @system_config.disable_shared_socket,
         
     | 
| 
      
 787 
     | 
    
         
            +
                    'restart_worker_interval' => @system_config.restart_worker_interval,
         
     | 
| 
      
 788 
     | 
    
         
            +
                  }
         
     | 
| 
      
 789 
     | 
    
         
            +
             
     | 
| 
      
 790 
     | 
    
         
            +
                  se = ServerEngine.create(ServerModule, WorkerModule) {
         
     | 
| 
      
 791 
     | 
    
         
            +
                    # Note: This is called only at the initialization of ServerEngine, since
         
     | 
| 
      
 792 
     | 
    
         
            +
                    # Fluentd overwrites all related SIGNAL(HUP,USR1,USR2) and have own reloading feature.
         
     | 
| 
      
 793 
     | 
    
         
            +
                    Fluent::Supervisor.serverengine_config(params)
         
     | 
| 
      
 794 
     | 
    
         
            +
                  }
         
     | 
| 
      
 795 
     | 
    
         
            +
             
     | 
| 
      
 796 
     | 
    
         
            +
                  se.run
         
     | 
| 
      
 797 
     | 
    
         
            +
                end
         
     | 
| 
      
 798 
     | 
    
         
            +
             
     | 
| 
      
 799 
     | 
    
         
            +
                def install_main_process_signal_handlers
         
     | 
| 
      
 800 
     | 
    
         
            +
                  # Fluentd worker process (worker of ServerEngine) don't use code in serverengine to set signal handlers,
         
     | 
| 
      
 801 
     | 
    
         
            +
                  # because it does almost nothing.
         
     | 
| 
      
 802 
     | 
    
         
            +
                  # This method is the only method to set signal handlers in Fluentd worker process.
         
     | 
| 
      
 803 
     | 
    
         
            +
             
     | 
| 
      
 804 
     | 
    
         
            +
                  # When user use Ctrl + C not SIGINT, SIGINT is sent to all process in same process group.
         
     | 
| 
      
 805 
     | 
    
         
            +
                  # ServerEngine server process will send SIGTERM to child(spawned) processes by that SIGINT, so
         
     | 
| 
      
 806 
     | 
    
         
            +
                  # worker process SHOULD NOT do anything with SIGINT, SHOULD just ignore.
         
     | 
| 
      
 807 
     | 
    
         
            +
                  trap :INT do
         
     | 
| 
      
 808 
     | 
    
         
            +
                    $log.debug "fluentd main process get SIGINT"
         
     | 
| 
      
 809 
     | 
    
         
            +
             
     | 
| 
      
 810 
     | 
    
         
            +
                    # When Fluentd is launched without supervisor, worker should handle ctrl-c by itself
         
     | 
| 
      
 811 
     | 
    
         
            +
                    if @standalone_worker
         
     | 
| 
      
 812 
     | 
    
         
            +
                      @finished = true
         
     | 
| 
      
 813 
     | 
    
         
            +
                      $log.debug "getting start to shutdown main process"
         
     | 
| 
      
 814 
     | 
    
         
            +
                      Fluent::Engine.stop
         
     | 
| 
      
 815 
     | 
    
         
            +
                    end
         
     | 
| 
      
 816 
     | 
    
         
            +
                  end
         
     | 
| 
      
 817 
     | 
    
         
            +
             
     | 
| 
      
 818 
     | 
    
         
            +
                  trap :TERM do
         
     | 
| 
      
 819 
     | 
    
         
            +
                    $log.debug "fluentd main process get SIGTERM"
         
     | 
| 
      
 820 
     | 
    
         
            +
                    unless @finished
         
     | 
| 
      
 821 
     | 
    
         
            +
                      @finished = true
         
     | 
| 
      
 822 
     | 
    
         
            +
                      $log.debug "getting start to shutdown main process"
         
     | 
| 
      
 823 
     | 
    
         
            +
                      Fluent::Engine.stop
         
     | 
| 
      
 824 
     | 
    
         
            +
                    end
         
     | 
| 
      
 825 
     | 
    
         
            +
                  end
         
     | 
| 
      
 826 
     | 
    
         
            +
             
     | 
| 
      
 827 
     | 
    
         
            +
                  if Fluent.windows?
         
     | 
| 
      
 828 
     | 
    
         
            +
                    install_main_process_command_handlers
         
     | 
| 
      
 829 
     | 
    
         
            +
                  else
         
     | 
| 
      
 830 
     | 
    
         
            +
                    trap :USR1 do
         
     | 
| 
      
 831 
     | 
    
         
            +
                      flush_buffer
         
     | 
| 
      
 832 
     | 
    
         
            +
                    end
         
     | 
| 
      
 833 
     | 
    
         
            +
             
     | 
| 
      
 834 
     | 
    
         
            +
                    trap :USR2 do
         
     | 
| 
      
 835 
     | 
    
         
            +
                      reload_config
         
     | 
| 
      
 836 
     | 
    
         
            +
                    end
         
     | 
| 
      
 837 
     | 
    
         
            +
             
     | 
| 
      
 838 
     | 
    
         
            +
                    trap :CONT do
         
     | 
| 
      
 839 
     | 
    
         
            +
                      dump_non_windows
         
     | 
| 
      
 840 
     | 
    
         
            +
                    end
         
     | 
| 
      
 841 
     | 
    
         
            +
                  end
         
     | 
| 
      
 842 
     | 
    
         
            +
                end
         
     | 
| 
      
 843 
     | 
    
         
            +
             
     | 
| 
      
 844 
     | 
    
         
            +
                def install_main_process_command_handlers
         
     | 
| 
      
 845 
     | 
    
         
            +
                  command_pipe = $stdin.dup
         
     | 
| 
      
 846 
     | 
    
         
            +
                  $stdin.reopen(File::NULL, "rb")
         
     | 
| 
      
 847 
     | 
    
         
            +
                  command_pipe.binmode
         
     | 
| 
      
 848 
     | 
    
         
            +
                  command_pipe.sync = true
         
     | 
| 
      
 849 
     | 
    
         
            +
             
     | 
| 
      
 850 
     | 
    
         
            +
                  Thread.new do
         
     | 
| 
      
 851 
     | 
    
         
            +
                    loop do
         
     | 
| 
      
 852 
     | 
    
         
            +
                      cmd = command_pipe.gets
         
     | 
| 
      
 853 
     | 
    
         
            +
                      break unless cmd
         
     | 
| 
      
 854 
     | 
    
         
            +
             
     | 
| 
      
 855 
     | 
    
         
            +
                      case cmd.chomp!
         
     | 
| 
      
 856 
     | 
    
         
            +
                      when "GRACEFUL_STOP", "IMMEDIATE_STOP"
         
     | 
| 
      
 857 
     | 
    
         
            +
                        $log.debug "fluentd main process get #{cmd} command"
         
     | 
| 
      
 858 
     | 
    
         
            +
                        @finished = true
         
     | 
| 
      
 859 
     | 
    
         
            +
                        $log.debug "getting start to shutdown main process"
         
     | 
| 
      
 860 
     | 
    
         
            +
                        Fluent::Engine.stop
         
     | 
| 
      
 861 
     | 
    
         
            +
                        break
         
     | 
| 
      
 862 
     | 
    
         
            +
                      when "GRACEFUL_RESTART"
         
     | 
| 
      
 863 
     | 
    
         
            +
                        $log.debug "fluentd main process get #{cmd} command"
         
     | 
| 
      
 864 
     | 
    
         
            +
                        flush_buffer
         
     | 
| 
      
 865 
     | 
    
         
            +
                      when "RELOAD"
         
     | 
| 
      
 866 
     | 
    
         
            +
                        $log.debug "fluentd main process get #{cmd} command"
         
     | 
| 
      
 867 
     | 
    
         
            +
                        reload_config
         
     | 
| 
      
 868 
     | 
    
         
            +
                      when "DUMP"
         
     | 
| 
      
 869 
     | 
    
         
            +
                        $log.debug "fluentd main process get #{cmd} command"
         
     | 
| 
      
 870 
     | 
    
         
            +
                        dump_windows
         
     | 
| 
      
 871 
     | 
    
         
            +
                      else
         
     | 
| 
      
 872 
     | 
    
         
            +
                        $log.warn "fluentd main process get unknown command [#{cmd}]"
         
     | 
| 
      
 873 
     | 
    
         
            +
                      end
         
     | 
| 
      
 874 
     | 
    
         
            +
                    end
         
     | 
| 
      
 875 
     | 
    
         
            +
                  end
         
     | 
| 
      
 876 
     | 
    
         
            +
                end
         
     | 
| 
      
 877 
     | 
    
         
            +
             
     | 
| 
      
 878 
     | 
    
         
            +
                def flush_buffer
         
     | 
| 
      
 879 
     | 
    
         
            +
                  # Creating new thread due to mutex can't lock
         
     | 
| 
      
 880 
     | 
    
         
            +
                  # in main thread during trap context
         
     | 
| 
      
 881 
     | 
    
         
            +
                  Thread.new do
         
     | 
| 
      
 882 
     | 
    
         
            +
                    begin
         
     | 
| 
      
 883 
     | 
    
         
            +
                      $log.debug "fluentd main process get SIGUSR1"
         
     | 
| 
      
 884 
     | 
    
         
            +
                      $log.info "force flushing buffered events"
         
     | 
| 
      
 885 
     | 
    
         
            +
                      $log.reopen!
         
     | 
| 
      
 886 
     | 
    
         
            +
                      Fluent::Engine.flush!
         
     | 
| 
      
 887 
     | 
    
         
            +
                      $log.debug "flushing thread: flushed"
         
     | 
| 
      
 888 
     | 
    
         
            +
                    rescue Exception => e
         
     | 
| 
      
 889 
     | 
    
         
            +
                      $log.warn "flushing thread error: #{e}"
         
     | 
| 
      
 890 
     | 
    
         
            +
                    end
         
     | 
| 
      
 891 
     | 
    
         
            +
                  end
         
     | 
| 
      
 892 
     | 
    
         
            +
                end
         
     | 
| 
      
 893 
     | 
    
         
            +
             
     | 
| 
      
 894 
     | 
    
         
            +
                def reload_config
         
     | 
| 
      
 895 
     | 
    
         
            +
                  Thread.new do
         
     | 
| 
      
 896 
     | 
    
         
            +
                    $log.debug('worker got SIGUSR2')
         
     | 
| 
      
 897 
     | 
    
         
            +
             
     | 
| 
      
 898 
     | 
    
         
            +
                    begin
         
     | 
| 
      
 899 
     | 
    
         
            +
                      conf = Fluent::Config.build(
         
     | 
| 
      
 900 
     | 
    
         
            +
                        config_path: @config_path,
         
     | 
| 
      
 901 
     | 
    
         
            +
                        encoding: @conf_encoding,
         
     | 
| 
      
 902 
     | 
    
         
            +
                        additional_config: @inline_config,
         
     | 
| 
      
 903 
     | 
    
         
            +
                        use_v1_config: @use_v1_config,
         
     | 
| 
      
 904 
     | 
    
         
            +
                        type: @config_file_type,
         
     | 
| 
      
 905 
     | 
    
         
            +
                      )
         
     | 
| 
      
 906 
     | 
    
         
            +
             
     | 
| 
      
 907 
     | 
    
         
            +
                      Fluent::VariableStore.try_to_reset do
         
     | 
| 
      
 908 
     | 
    
         
            +
                        Fluent::Engine.reload_config(conf)
         
     | 
| 
      
 909 
     | 
    
         
            +
                      end
         
     | 
| 
      
 910 
     | 
    
         
            +
                    rescue => e
         
     | 
| 
      
 911 
     | 
    
         
            +
                      # it is guaranteed that config file is valid by supervisor side. but it's not atomic because of using signals to commnicate between worker and super
         
     | 
| 
      
 912 
     | 
    
         
            +
                      # So need this rescue code
         
     | 
| 
      
 913 
     | 
    
         
            +
                      $log.error("failed to reload config: #{e}")
         
     | 
| 
      
 914 
     | 
    
         
            +
                      next
         
     | 
| 
      
 915 
     | 
    
         
            +
                    end
         
     | 
| 
      
 916 
     | 
    
         
            +
             
     | 
| 
      
 917 
     | 
    
         
            +
                    @conf = conf
         
     | 
| 
      
 918 
     | 
    
         
            +
                  end
         
     | 
| 
      
 919 
     | 
    
         
            +
                end
         
     | 
| 
      
 920 
     | 
    
         
            +
             
     | 
| 
      
 921 
     | 
    
         
            +
                def dump_non_windows
         
     | 
| 
      
 922 
     | 
    
         
            +
                  begin
         
     | 
| 
      
 923 
     | 
    
         
            +
                    Sigdump.dump unless @finished
         
     | 
| 
      
 924 
     | 
    
         
            +
                  rescue => e
         
     | 
| 
      
 925 
     | 
    
         
            +
                    $log.error("failed to dump: #{e}")
         
     | 
| 
      
 926 
     | 
    
         
            +
                  end
         
     | 
| 
      
 927 
     | 
    
         
            +
                end
         
     | 
| 
      
 928 
     | 
    
         
            +
             
     | 
| 
      
 929 
     | 
    
         
            +
                def dump_windows
         
     | 
| 
      
 930 
     | 
    
         
            +
                  Thread.new do
         
     | 
| 
      
 931 
     | 
    
         
            +
                    begin
         
     | 
| 
      
 932 
     | 
    
         
            +
                      FluentSigdump.dump_windows
         
     | 
| 
      
 933 
     | 
    
         
            +
                    rescue => e
         
     | 
| 
      
 934 
     | 
    
         
            +
                      $log.error("failed to dump: #{e}")
         
     | 
| 
      
 935 
     | 
    
         
            +
                    end
         
     | 
| 
      
 936 
     | 
    
         
            +
                  end
         
     | 
| 
      
 937 
     | 
    
         
            +
                end
         
     | 
| 
      
 938 
     | 
    
         
            +
             
     | 
| 
      
 939 
     | 
    
         
            +
                def logging_with_console_output
         
     | 
| 
      
 940 
     | 
    
         
            +
                  yield $log
         
     | 
| 
      
 941 
     | 
    
         
            +
                  unless $log.stdout?
         
     | 
| 
      
 942 
     | 
    
         
            +
                    logger = ServerEngine::DaemonLogger.new(STDOUT)
         
     | 
| 
      
 943 
     | 
    
         
            +
                    log = Fluent::Log.new(logger)
         
     | 
| 
      
 944 
     | 
    
         
            +
                    log.level = @system_config.log_level
         
     | 
| 
      
 945 
     | 
    
         
            +
                    console = log.enable_debug
         
     | 
| 
      
 946 
     | 
    
         
            +
                    yield console
         
     | 
| 
      
 947 
     | 
    
         
            +
                  end
         
     | 
| 
      
 948 
     | 
    
         
            +
                end
         
     | 
| 
      
 949 
     | 
    
         
            +
             
     | 
| 
      
 950 
     | 
    
         
            +
                def main_process(&block)
         
     | 
| 
      
 951 
     | 
    
         
            +
                  if @system_config.process_name
         
     | 
| 
      
 952 
     | 
    
         
            +
                    if @system_config.workers > 1
         
     | 
| 
      
 953 
     | 
    
         
            +
                      Process.setproctitle("worker:#{@system_config.process_name}#{ENV['SERVERENGINE_WORKER_ID']}")
         
     | 
| 
      
 954 
     | 
    
         
            +
                    else
         
     | 
| 
      
 955 
     | 
    
         
            +
                      Process.setproctitle("worker:#{@system_config.process_name}")
         
     | 
| 
      
 956 
     | 
    
         
            +
                    end
         
     | 
| 
      
 957 
     | 
    
         
            +
                  end
         
     | 
| 
      
 958 
     | 
    
         
            +
             
     | 
| 
      
 959 
     | 
    
         
            +
                  unrecoverable_error = false
         
     | 
| 
      
 960 
     | 
    
         
            +
             
     | 
| 
      
 961 
     | 
    
         
            +
                  begin
         
     | 
| 
      
 962 
     | 
    
         
            +
                    block.call
         
     | 
| 
      
 963 
     | 
    
         
            +
                  rescue Fluent::ConfigError => e
         
     | 
| 
      
 964 
     | 
    
         
            +
                    logging_with_console_output do |log|
         
     | 
| 
      
 965 
     | 
    
         
            +
                      log.error "config error", file: @config_path, error: e
         
     | 
| 
      
 966 
     | 
    
         
            +
                      log.debug_backtrace
         
     | 
| 
      
 967 
     | 
    
         
            +
                    end
         
     | 
| 
      
 968 
     | 
    
         
            +
                    unrecoverable_error = true
         
     | 
| 
      
 969 
     | 
    
         
            +
                  rescue Fluent::UnrecoverableError => e
         
     | 
| 
      
 970 
     | 
    
         
            +
                    logging_with_console_output do |log|
         
     | 
| 
      
 971 
     | 
    
         
            +
                      log.error e.message, error: e
         
     | 
| 
      
 972 
     | 
    
         
            +
                      log.error_backtrace
         
     | 
| 
      
 973 
     | 
    
         
            +
                    end
         
     | 
| 
      
 974 
     | 
    
         
            +
                    unrecoverable_error = true
         
     | 
| 
      
 975 
     | 
    
         
            +
                  rescue ScriptError => e # LoadError, NotImplementedError, SyntaxError
         
     | 
| 
      
 976 
     | 
    
         
            +
                    logging_with_console_output do |log|
         
     | 
| 
      
 977 
     | 
    
         
            +
                      if e.respond_to?(:path)
         
     | 
| 
      
 978 
     | 
    
         
            +
                        log.error e.message, path: e.path, error: e
         
     | 
| 
      
 979 
     | 
    
         
            +
                      else
         
     | 
| 
      
 980 
     | 
    
         
            +
                        log.error e.message, error: e
         
     | 
| 
      
 981 
     | 
    
         
            +
                      end
         
     | 
| 
      
 982 
     | 
    
         
            +
                      log.error_backtrace
         
     | 
| 
      
 983 
     | 
    
         
            +
                    end
         
     | 
| 
      
 984 
     | 
    
         
            +
                    unrecoverable_error = true
         
     | 
| 
      
 985 
     | 
    
         
            +
                  rescue => e
         
     | 
| 
      
 986 
     | 
    
         
            +
                    logging_with_console_output do |log|
         
     | 
| 
      
 987 
     | 
    
         
            +
                      log.error "unexpected error", error: e
         
     | 
| 
      
 988 
     | 
    
         
            +
                      log.error_backtrace
         
     | 
| 
      
 989 
     | 
    
         
            +
                    end
         
     | 
| 
      
 990 
     | 
    
         
            +
                  end
         
     | 
| 
      
 991 
     | 
    
         
            +
             
     | 
| 
      
 992 
     | 
    
         
            +
                  exit!(unrecoverable_error ? 2 : 1)
         
     | 
| 
      
 993 
     | 
    
         
            +
                end
         
     | 
| 
      
 994 
     | 
    
         
            +
             
     | 
| 
      
 995 
     | 
    
         
            +
                def build_system_config(conf)
         
     | 
| 
      
 996 
     | 
    
         
            +
                  system_config = SystemConfig.create(conf, @cl_opt[:strict_config_value])
         
     | 
| 
      
 997 
     | 
    
         
            +
                  # Prefer the options explicitly specified in the command line
         
     | 
| 
      
 998 
     | 
    
         
            +
                  # 
         
     | 
| 
      
 999 
     | 
    
         
            +
                  # TODO: There is a bug that `system_config.log.rotate_age/rotate_size` are
         
     | 
| 
      
 1000 
     | 
    
         
            +
                  # not merged with the command line options since they are not in
         
     | 
| 
      
 1001 
     | 
    
         
            +
                  # `SYSTEM_CONFIG_PARAMETERS`.
         
     | 
| 
      
 1002 
     | 
    
         
            +
                  # We have to fix this bug.
         
     | 
| 
      
 1003 
     | 
    
         
            +
                  opt = {}
         
     | 
| 
      
 1004 
     | 
    
         
            +
                  Fluent::SystemConfig::SYSTEM_CONFIG_PARAMETERS.each do |param|
         
     | 
| 
      
 1005 
     | 
    
         
            +
                    if @cl_opt.key?(param) && !@cl_opt[param].nil?
         
     | 
| 
      
 1006 
     | 
    
         
            +
                      opt[param] = @cl_opt[param]
         
     | 
| 
      
 1007 
     | 
    
         
            +
                    end
         
     | 
| 
      
 1008 
     | 
    
         
            +
                  end
         
     | 
| 
      
 1009 
     | 
    
         
            +
                  system_config.overwrite_variables(**opt)
         
     | 
| 
      
 1010 
     | 
    
         
            +
                  system_config
         
     | 
| 
      
 1011 
     | 
    
         
            +
                end
         
     | 
| 
      
 1012 
     | 
    
         
            +
             
     | 
| 
      
 1013 
     | 
    
         
            +
                RUBY_ENCODING_OPTIONS_REGEX = %r{\A(-E|--encoding=|--internal-encoding=|--external-encoding=)}.freeze
         
     | 
| 
      
 1014 
     | 
    
         
            +
             
     | 
| 
      
 1015 
     | 
    
         
            +
                def build_spawn_command
         
     | 
| 
      
 1016 
     | 
    
         
            +
                  if ENV['TEST_RUBY_PATH']
         
     | 
| 
      
 1017 
     | 
    
         
            +
                    fluentd_spawn_cmd = [ENV['TEST_RUBY_PATH']]
         
     | 
| 
      
 1018 
     | 
    
         
            +
                  else
         
     | 
| 
      
 1019 
     | 
    
         
            +
                    fluentd_spawn_cmd = [ServerEngine.ruby_bin_path]
         
     | 
| 
      
 1020 
     | 
    
         
            +
                  end
         
     | 
| 
      
 1021 
     | 
    
         
            +
             
     | 
| 
      
 1022 
     | 
    
         
            +
                  rubyopt = ENV['RUBYOPT']
         
     | 
| 
      
 1023 
     | 
    
         
            +
                  if rubyopt
         
     | 
| 
      
 1024 
     | 
    
         
            +
                    encodes, others = rubyopt.split(' ').partition { |e| e.match?(RUBY_ENCODING_OPTIONS_REGEX) }
         
     | 
| 
      
 1025 
     | 
    
         
            +
                    fluentd_spawn_cmd.concat(others)
         
     | 
| 
      
 1026 
     | 
    
         
            +
             
     | 
| 
      
 1027 
     | 
    
         
            +
                    adopted_encodes = encodes.empty? ? ['-Eascii-8bit:ascii-8bit'] : encodes
         
     | 
| 
      
 1028 
     | 
    
         
            +
                    fluentd_spawn_cmd.concat(adopted_encodes)
         
     | 
| 
      
 1029 
     | 
    
         
            +
                  else
         
     | 
| 
      
 1030 
     | 
    
         
            +
                    fluentd_spawn_cmd << '-Eascii-8bit:ascii-8bit'
         
     | 
| 
      
 1031 
     | 
    
         
            +
                  end
         
     | 
| 
      
 1032 
     | 
    
         
            +
             
     | 
| 
      
 1033 
     | 
    
         
            +
                  if @system_config.enable_jit
         
     | 
| 
      
 1034 
     | 
    
         
            +
                    $log.info "enable Ruby JIT for workers (--jit)"
         
     | 
| 
      
 1035 
     | 
    
         
            +
                    fluentd_spawn_cmd << '--jit'
         
     | 
| 
      
 1036 
     | 
    
         
            +
                  end
         
     | 
| 
      
 1037 
     | 
    
         
            +
             
     | 
| 
      
 1038 
     | 
    
         
            +
                  # Adding `-h` so that it can avoid ruby's command blocking
         
     | 
| 
      
 1039 
     | 
    
         
            +
                  # e.g. `ruby -Eascii-8bit:ascii-8bit` will block. but `ruby -Eascii-8bit:ascii-8bit -h` won't.
         
     | 
| 
      
 1040 
     | 
    
         
            +
                  _, e, s = Open3.capture3(*fluentd_spawn_cmd, "-h")
         
     | 
| 
      
 1041 
     | 
    
         
            +
                  if s.exitstatus != 0
         
     | 
| 
      
 1042 
     | 
    
         
            +
                    $log.error('Invalid option is passed to RUBYOPT', command: fluentd_spawn_cmd, error: e)
         
     | 
| 
      
 1043 
     | 
    
         
            +
                    exit s.exitstatus
         
     | 
| 
      
 1044 
     | 
    
         
            +
                  end
         
     | 
| 
      
 1045 
     | 
    
         
            +
             
     | 
| 
      
 1046 
     | 
    
         
            +
                  fluentd_spawn_cmd << $0
         
     | 
| 
      
 1047 
     | 
    
         
            +
                  fluentd_spawn_cmd += $fluentdargv
         
     | 
| 
      
 1048 
     | 
    
         
            +
                  fluentd_spawn_cmd << '--under-supervisor'
         
     | 
| 
      
 1049 
     | 
    
         
            +
             
     | 
| 
      
 1050 
     | 
    
         
            +
                  fluentd_spawn_cmd
         
     | 
| 
      
 1051 
     | 
    
         
            +
                end
         
     | 
| 
      
 1052 
     | 
    
         
            +
              end
         
     | 
| 
      
 1053 
     | 
    
         
            +
             
     | 
| 
      
 1054 
     | 
    
         
            +
              module FluentSigdump
         
     | 
| 
      
 1055 
     | 
    
         
            +
                def self.dump_windows
         
     | 
| 
      
 1056 
     | 
    
         
            +
                  raise "[BUG] WindowsSigdump::dump is for Windows ONLY." unless Fluent.windows?
         
     | 
| 
      
 1057 
     | 
    
         
            +
             
     | 
| 
      
 1058 
     | 
    
         
            +
                  # Sigdump outputs under `/tmp` dir without `SIGDUMP_PATH` specified,
         
     | 
| 
      
 1059 
     | 
    
         
            +
                  # but `/tmp` dir may not exist on Windows by default.
         
     | 
| 
      
 1060 
     | 
    
         
            +
                  # So use the systemroot-temp-dir instead.
         
     | 
| 
      
 1061 
     | 
    
         
            +
                  dump_filepath = ENV['SIGDUMP_PATH'].nil? || ENV['SIGDUMP_PATH'].empty? \
         
     | 
| 
      
 1062 
     | 
    
         
            +
                    ? "#{ENV['windir']}/Temp/fluentd-sigdump-#{Process.pid}.log"
         
     | 
| 
      
 1063 
     | 
    
         
            +
                    : get_path_with_pid(ENV['SIGDUMP_PATH'])
         
     | 
| 
      
 1064 
     | 
    
         
            +
             
     | 
| 
      
 1065 
     | 
    
         
            +
                  require 'sigdump'
         
     | 
| 
      
 1066 
     | 
    
         
            +
                  Sigdump.dump(dump_filepath)
         
     | 
| 
      
 1067 
     | 
    
         
            +
             
     | 
| 
      
 1068 
     | 
    
         
            +
                  $log.info "dump to #{dump_filepath}."
         
     | 
| 
      
 1069 
     | 
    
         
            +
                end
         
     | 
| 
      
 1070 
     | 
    
         
            +
             
     | 
| 
      
 1071 
     | 
    
         
            +
                def self.get_path_with_pid(raw_path)
         
     | 
| 
      
 1072 
     | 
    
         
            +
                  path = Pathname.new(raw_path)
         
     | 
| 
      
 1073 
     | 
    
         
            +
                  path.sub_ext("-#{Process.pid}#{path.extname}").to_s
         
     | 
| 
      
 1074 
     | 
    
         
            +
                end
         
     | 
| 
      
 1075 
     | 
    
         
            +
              end
         
     | 
| 
      
 1076 
     | 
    
         
            +
            end
         
     |