Module: Promotion::Generator::Rcconf

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

Class Method Summary collapse

Class Method Details

.contents(specs) ⇒ Object

Generates the contents for /etc/rc.conf.local, containing instructions for running daemons



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
# File 'lib/promotion/generator/rcconf.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"
  contents << "# ---------------------------\n"
  contents << "# generated application flags\n"
  daemonSpecs = specs.reject {|s| s.elements["/Specification/Daemon"].nil? }
  daemonSpecs.sort!() { |a, b|
    ap = a.elements["/Specification/Daemon"].attributes["Priority"].to_i || 10
    bp = b.elements["/Specification/Daemon"].attributes["Priority"].to_i || 10
    ap <=> bp
  }
  pkgScripts = []
  daemonSpecs.each { |spec|
    name = spec.attributes["Name"]
    flags = spec.elements["/Specification/Daemon"].attributes["Flags"]
    contents << "#{name}_flags=\"#{flags}\" \n"
    pkgScripts << name
  }
  contents << "# rc.d(8) packages scripts\n"
  contents << "# started in the specified order and stopped in reverse order\n"
  contents << "pkg_scripts=\"#{pkgScripts.join(" ")}\" \n"
  return(contents.join(""))
end

.generate(specs) ⇒ Object

Writes the system file /etc/rc.conf.local



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

def self.generate(specs)
  sym = "Rc_conf"
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