From 75ef92f787106de0a054174c2423a7f2fee00350 Mon Sep 17 00:00:00 2001 From: Fujimoto Seiji Date: Fri, 1 Jul 2022 11:50:57 +0900 Subject: [PATCH] Use automatic cleanup with FLUENTD_LOCKDIR This is a lot safer than doing a manual cleanup, and it also allows to clean up directories in a more rubust manner. Signed-off-by: Fujimoto Seiji --- lib/fluent/supervisor.rb | 15 +++++---------- 1 file changed, 5 insertions(+), 10 deletions(-) diff --git a/lib/fluent/supervisor.rb b/lib/fluent/supervisor.rb index cab076c50c..079eb4709b 100644 --- a/lib/fluent/supervisor.rb +++ b/lib/fluent/supervisor.rb @@ -50,9 +50,6 @@ def before_run @rpc_server = nil @counter = nil - @fluentd_lockdir = Dir.mktmpdir("fluentd-lock-") - ENV['FLUENTD_LOCKDIR'] = @fluentd_lockdir - if config[:rpc_endpoint] @rpc_endpoint = config[:rpc_endpoint] @enable_get_dump = config[:enable_get_dump] @@ -82,15 +79,9 @@ def after_run stop_windows_event_thread if Fluent.windows? stop_rpc_server if @rpc_endpoint stop_counter_server if @counter - cleanup_lockdir Fluent::Supervisor.cleanup_resources end - def cleanup_lockdir - FileUtils.rm(Dir.glob(File.join(@fluentd_lockdir, "fluentd-*.lock"))) - FileUtils.rmdir(@fluentd_lockdir) - end - def run_rpc_server @rpc_server = RPC::Server.new(@rpc_endpoint, $log) @@ -884,7 +875,11 @@ def supervise se = ServerEngine.create(ServerModule, WorkerModule){ Fluent::Supervisor.load_config(@config_path, params) } - se.run + + Dir.mktmpdir("fluentd-lock-") do |lockdir| + ENV['FLUENTD_LOCKDIR'] = lockdir + se.run + end end def install_main_process_signal_handlers