Module: Promotion::Generator::Newsyslog

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

Class Method Summary collapse

Class Method Details

.contents(specs) ⇒ Object

Generates the contents for /etc/newsyslog.conf, which controls rolling and retention of logs



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
49
50
51
52
53
54
55
56
# File 'lib/promotion/generator/newsyslog.rb', line 19

def self.contents(specs)
  contents = []
  contents << "# This section of the file should not be edited\n"
  contents << "# It was generated by the promotion application and will be overwritten\n"
  contents << "# when the next promotion occurs.\n"
  contents << "# The previous section will be preserved\n\n"
  contents << "# Filename                              Owner:Group         Mode   Count  Size   When     Flags\n"
  specs.each { |spec|
    spec.elements.each("/Specification/Newsyslog") { |nsl|
      contents << "%-40s" % nsl.text()
      owner = nsl.attributes["Owner"]
      group = nsl.attributes["Group"]
      if owner.nil? or group.nil?
          og = ""
      else
          og = owner + ":" + group
      end
      contents << "%-20s" % og
      contents << "%-7s" % (nsl.attributes["Mode"] || "0640")
      contents << "%-7s" % (nsl.attributes["Count"] || "*")
      contents << "%-7s" % (nsl.attributes["Size"] || "*")
      # 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"
        contents << "$%-9s" % sched
      elsif sched.include?("T")
        contents << "@%-9s" % sched
      else
        contents << "%-9s" % sched
      end
      contents << "Z" if (nsl.attributes["Zip"] || "true") == "true"
      contents << "B" if (nsl.attributes["Binary"] || "false") == "true"
      contents << "\n"
    }
  }
  return(contents.join(""))
end

.generate(specs) ⇒ Object

Writes the Newsyslog configuration



6
7
8
9
10
11
12
13
14
15
16
# File 'lib/promotion/generator/newsyslog.rb', line 6

def self.generate(specs)
  sym = "Newsyslog"
  begin
    originalContents = Promotion::Generator::original_contents_for(sym)
    newContents = originalContents + Marker + "\n" + contents(specs)
    Promotion::Generator::write_file_for(sym, newContents)
  rescue => e
    $log.error("Error occurred while generating #{sym}\n#{e.message}" + e.backtrace.join("\n"))
    exit 1
  end
end