Parent

Unicorn::Util

Public Class Methods

chown_logs(uid, gid) click to toggle source

(Not documented)

    # File lib/unicorn/util.rb, line 29
29:       def chown_logs(uid, gid)
30:         ObjectSpace.each_object(File) do |fp|
31:           fp.chown(uid, gid) if is_log?(fp)
32:         end
33:       end
is_log?(fp) click to toggle source

(Not documented)

    # File lib/unicorn/util.rb, line 20
20:       def is_log?(fp)
21:         append_flags = File::WRONLY | File::APPEND
22: 
23:         ! fp.closed? &&
24:           fp.sync &&
25:           fp.path[0] == ?/ &&
26:           (fp.fcntl(Fcntl::F_GETFL) & append_flags) == append_flags
27:       end
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) opened with an absolute path (starts with "/")
  3) the current open file handle does not match its original open path
  4) unbuffered (as far as userspace buffering goes, not O_SYNC)

Returns the number of files reopened

    # File lib/unicorn/util.rb, line 43
43:       def reopen_logs
44:         nr = 0
45: 
46:         ObjectSpace.each_object(File) do |fp|
47:           is_log?(fp) or next
48:           orig_st = fp.stat
49:           begin
50:             b = File.stat(fp.path)
51:             next if orig_st.ino == b.ino && orig_st.dev == b.dev
52:           rescue Errno::ENOENT
53:           end
54: 
55:           open_arg = 'a'
56:           if fp.respond_to?(:external_encoding) && enc = fp.external_encoding
57:             open_arg << ":#{enc.to_s}"
58:             enc = fp.internal_encoding and open_arg << ":#{enc.to_s}"
59:           end
60:           fp.reopen(fp.path, open_arg)
61:           fp.sync = true
62:           new_st = fp.stat
63:           if orig_st.uid != new_st.uid || orig_st.gid != new_st.gid
64:             fp.chown(orig_st.uid, orig_st.gid)
65:           end
66:           nr += 1
67:         end # each_object
68:         nr
69:       end
tmpio() click to toggle source

creates and returns a new File object. The File is unlinked immediately, switched to binary mode, and userspace output buffering is disabled

    # File lib/unicorn/util.rb, line 74
74:       def tmpio
75:         fp = begin
76:           TmpIO.open("#{Dir::tmpdir}/#{rand}",
77:                      File::RDWR|File::CREAT|File::EXCL, 0600)
78:         rescue Errno::EEXIST
79:           retry
80:         end
81:         File.unlink(fp.path)
82:         fp.binmode
83:         fp.sync = true
84:         fp
85:       end

Disabled; run with --debug to generate this.

[Validate]

Generated with the Darkfish Rdoc Generator 1.1.6.