Module: FileDaemon::ClassMethods

Defined in:
lib/file_daemon.rb

Overview

:nodoc:

Instance Method Summary collapse

Instance Method Details

#after_forkObject

Public: Reopen all file descriptors that have been stored through the before_fork hook.

Returns nothing.



30
31
32
33
34
35
36
37
38
# File 'lib/file_daemon.rb', line 30

def after_fork
  @files_to_reopen.each do |file|
    begin
      file.reopen file.path, "a+"
      file.sync = true
    rescue ::IOError # rubocop:disable HandleExceptions
    end
  end
end

#before_forkObject

Public: Store the list of currently open file descriptors so that they may be reopened when a new process is spawned.

Returns nothing.



22
23
24
# File 'lib/file_daemon.rb', line 22

def before_fork
  @files_to_reopen ||= ObjectSpace.each_object(File).reject(&:closed?)
end