Methods

Unicorn::Util

Public Class Methods

reopen_logs() click to toggle source

This reopens ALL logfiles in the process that have been rotated using logrotate(8) (without copytruncate) or similar tools. A File object is considered for reopening if it is:

  1) opened with the O_APPEND and O_WRONLY flags
  2) the current open file handle does not match its original open path
  3) unbuffered (as far as userspace buffering goes, not O_SYNC)

Returns the number of files reopened

In Unicorn 3.5.x and earlier, files must be opened with an absolute path to be considered a log file.

    # File lib/unicorn/util.rb, line 33
33:   def self.reopen_logs
34:     to_reopen = []
35:     nr = 0
36:     ObjectSpace.each_object(File) { |fp| is_log?(fp) and to_reopen << fp }
37: 
38:     to_reopen.each do |fp|
39:       orig_st = begin
40:         fp.stat
41:       rescue IOError, Errno::EBADF
42:         next
43:       end
44: 
45:       begin
46:         b = File.stat(fp.path)
47:         next if orig_st.ino == b.ino && orig_st.dev == b.dev
48:       rescue Errno::ENOENT
49:       end
50: 
51:       begin
52:         File.open(fp.path, 'a') { |tmpfp| fp.reopen(tmpfp) }
53:         fp.sync = true
54:         new_st = fp.stat
55: 
56:         # this should only happen in the master:
57:         if orig_st.uid != new_st.uid || orig_st.gid != new_st.gid
58:           fp.chown(orig_st.uid, orig_st.gid)
59:         end
60: 
61:         nr += 1
62:       rescue IOError, Errno::EBADF
63:         # not much we can do...
64:       end
65:     end
66:     nr
67:   end

Disabled; run with --debug to generate this.

[Validate]

Generated with the Darkfish Rdoc Generator 1.1.6.