Skip to content

Commit

Permalink
Use automatic cleanup with FLUENTD_LOCKDIR
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
fujimotos committed Jul 1, 2022
1 parent a538b9b commit 75ef92f
Showing 1 changed file with 5 additions and 10 deletions.
15 changes: 5 additions & 10 deletions lib/fluent/supervisor.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down Expand Up @@ -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)

Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 75ef92f

Please sign in to comment.