module FileDaemon::ClassMethods

Public Instance Methods

after_fork() click to toggle source

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

Returns nothing.

# File lib/file_daemon.rb, line 39
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_fork() click to toggle source

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

Returns nothing.

# File lib/file_daemon.rb, line 31
def before_fork
  @files_to_reopen = ObjectSpace.each_object(File).reject(&:closed?)
end
reopen_files() click to toggle source

Public: Force-reopen all files at their current paths. Allows for rotation of log files outside of the context of an actual process fork.

Returns nothing.

# File lib/file_daemon.rb, line 22
def reopen_files
  before_fork
  after_fork
end