Class: Foreman::Export::MirApp

Inherits:
Base
  • Object
show all
Defined in:
lib/foreman/export/mir_app.rb

Instance Method Summary collapse

Instance Method Details

#exportObject



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/foreman/export/mir_app.rb', line 16

def export
  super

  engine.each_process do |name, process|
    1.upto(engine.formation[name]) do |num|
      proc_name = "#{app}-#{name}-#{num}"
      port      = engine.port_for(process, num)
      env       = engine.env.merge("PORT" => port)
      cmd       = process.command

      create_directory(proc_name)
      create_directory("#{proc_name}/env")
      create_directory("#{proc_name}/log")

      say "creating: #{log}/#{proc_name}"
      FileUtils.mkdir_p("#{log}/#{proc_name}")

      say "writing: #{log}/#{proc_name}/config"
      config = ERB.new(export_template('mir_app/log_config.erb'), nil, '-').result(binding)
      File.open("#{log}/#{proc_name}/config", "w") { |f| f.puts(config) }

      write_template('mir_app/run.erb', "#{proc_name}/run", binding)
      chmod(0755, "#{proc_name}/run")

      write_template('mir_app/log.erb', "#{proc_name}/log/run", binding)
      chmod(0755, "#{proc_name}/log/run")

      engine.env.each do |key, value|
        write_file("#{proc_name}/env/#{key}", value)
      end
    end
  end
end

#export_template(name, file = nil, template_root = nil) ⇒ Object



10
11
12
13
14
# File 'lib/foreman/export/mir_app.rb', line 10

def export_template(name, file=nil, template_root=nil)
  name_without_first = name.split("/")[1..-1].join("/")
  tpl = File.expand_path("../../../../data/export/#{name}", __FILE__)
  File.read(tpl)
end