Module: Promotion::Generator::Newsyslog

Defined in:
lib/promotion/generator/newsyslog.rb

Class Method Summary collapse

Class Method Details

.check(specs) ⇒ Object

Writes the Newsyslog configuration



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/promotion/generator/newsyslog.rb', line 6

def self.check(specs)
  contents = IO.readlines("/etc/newsyslog.conf").collect!{ |s| s.gsub(/\s/,"") }
  proposals = []
  specs.each { |spec|
    spec.elements.each("/Specification/Newsyslog") { |nsl|
      needed = nsl.text() << "\t"
      owner = nsl.attributes["Owner"]
      group = nsl.attributes["Group"]
      if owner.nil? or group.nil?
          og = ""
      else
          og = owner + ":" + group
      end
      needed << og << "\t"
      needed << (nsl.attributes["Mode"] || "0640") << "\t"
      needed << (nsl.attributes["Count"] || "*") << "\t"
      needed << (nsl.attributes["Size"] || "*") << "\t"
      # treat as $-format if starts with D,W,M; treat as integer if integer
      # else treat as @-format if digits with a 'T'
      sched = nsl.attributes["When"] || "*"
      if sched[0..0] == "D" or sched[0..0] == "W" or sched[0..0] == "M"
        needed << sched << "\t"
      elsif sched.include?("T")
        needed << "@" << sched << "\t"
      else
        needed << sched << "\t"
      end
      # We normally do not want to add rotation messages or compress
      needed << "Z" if (nsl.attributes["Zip"] || "false") == "true"
      needed << "B" if (nsl.attributes["Binary"] || "true") == "true"
      restart = nsl.attributes["Restart"]   # service to restart
      if restart
        needed << "\t/etc/rc.d/#{restart} restart >/dev/null 2>&1 "
      end
      # see if its already present - check the pattern ignoring whitespace
      proposals << needed unless contents.include?(needed.gsub(/\s/,""))
    }
  }
  if proposals.size > 0
    header = "# Filename\t\tOwner:Group\tMode\tCount\tSize\tWhen\tFlags\tCommand\n"
    puts("\nSuggested changes to /etc/newsyslog.conf:", header, proposals.join("\n"), "\n")
  end
end