Module: FileDaemon::ClassMethods
- Defined in:
- lib/file_daemon.rb
Overview
:nodoc:
Instance Method Summary collapse
-
#after_fork ⇒ Object
Public: Reopen all file descriptors that have been stored through the before_fork hook.
-
#before_fork ⇒ Object
Public: Store the list of currently open file descriptors so that they may be reopened when a new process is spawned.
-
#reopen_files ⇒ Object
Public: Force-reopen all files at their current paths.
Instance Method Details
#after_fork ⇒ Object
Public: Reopen all file descriptors that have been stored through the before_fork hook.
Returns nothing.
39 40 41 42 43 44 45 46 47 |
# 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 ⇒ Object
Public: Store the list of currently open file descriptors so that they may be reopened when a new process is spawned.
Returns nothing.
31 32 33 |
# File 'lib/file_daemon.rb', line 31 def before_fork @files_to_reopen = ObjectSpace.each_object(File).reject(&:closed?) end |
#reopen_files ⇒ Object
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.
22 23 24 25 |
# File 'lib/file_daemon.rb', line 22 def reopen_files before_fork after_fork end |