From 26425d80f0b5cbeadf41cbca4751f3bcda51f19a Mon Sep 17 00:00:00 2001 From: Fujimoto Seiji Date: Fri, 19 Aug 2022 09:36:25 +0900 Subject: [PATCH] Make the worker lock work in '--daemon' mode as well 75ef92f introduced automatic clean up as follows: Dir.mktmpdir("fluentd-lock-") do |lock_dir| ENV['FLUENTD_LOCK_DIR'] = lock_dir se.run end This does not work with `--daemon`, because `se.run` will not block with that option. Fix this issue by reverting to the manual clean up method in the initial version. Signed-off-by: Fujimoto Seiji --- lib/fluent/supervisor.rb | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/lib/fluent/supervisor.rb b/lib/fluent/supervisor.rb index 854e53cb12..a93205c2da 100644 --- a/lib/fluent/supervisor.rb +++ b/lib/fluent/supervisor.rb @@ -50,6 +50,9 @@ def before_run @rpc_server = nil @counter = nil + @fluentd_lock_dir = Dir.mktmpdir("fluentd-lock-") + ENV['FLUENTD_LOCK_DIR'] = @fluentd_lock_dir + if config[:rpc_endpoint] @rpc_endpoint = config[:rpc_endpoint] @enable_get_dump = config[:enable_get_dump] @@ -79,9 +82,15 @@ def after_run stop_windows_event_thread if Fluent.windows? stop_rpc_server if @rpc_endpoint stop_counter_server if @counter + cleanup_lock_dir Fluent::Supervisor.cleanup_resources end + def cleanup_lock_dir + FileUtils.rm(Dir.glob(File.join(@fluentd_lock_dir, "fluentd-*.lock"))) + FileUtils.rmdir(@fluentd_lock_dir) + end + def run_rpc_server @rpc_server = RPC::Server.new(@rpc_endpoint, $log) @@ -876,10 +885,7 @@ def supervise Fluent::Supervisor.load_config(@config_path, params) } - Dir.mktmpdir("fluentd-lock-") do |lock_dir| - ENV['FLUENTD_LOCK_DIR'] = lock_dir - se.run - end + se.run end def install_main_process_signal_handlers