Class: Foreman::Export::Runitu

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

Constant Summary collapse

ENV_VARIABLE_REGEX =
/([a-zA-Z_]+[a-zA-Z0-9_]*)=(\S+)/

Class Attribute Summary collapse

Instance Method Summary collapse

Class Attribute Details

.template_rootObject (readonly)

Returns the value of attribute template_root.



9
10
11
# File 'lib/foreman/export/runitu.rb', line 9

def template_root
  @template_root
end

Instance Method Details

#exportObject



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

def export
  template_root = Pathname.new(File.dirname(__FILE__)).join('../../../data/export/runitu').to_s

  engine.each_process do |name, process|
    1.upto(engine.formation[name]) do |num|
      process_directory = "#{app}-#{name}-#{num}"

      create_directory process_directory
      create_directory "#{process_directory}/env"
      create_directory "#{process_directory}/log"

      write_template "#{template_root}/run.erb", "#{process_directory}/run", binding
      chmod 0755, "#{process_directory}/run"

      port = engine.port_for(process, num)
      engine.env.merge("PORT" => port.to_s).each do |key, value|
        write_file "#{process_directory}/env/#{key}", value
      end

      write_template "#{template_root}/log/run.erb", "#{process_directory}/log/run", binding
      chmod 0755, "#{process_directory}/log/run"
    end
  end
end

#export_from_baseObject



14
15
16
17
18
19
# File 'lib/foreman/export/runitu.rb', line 14

def export_from_base
  error("Must specify a location") unless location
  FileUtils.mkdir_p(location) rescue error("Could not create: #{location}")
  FileUtils.mkdir_p(log) rescue error("Could not create: #{log}")
  #FileUtils.chown(user, nil, log) rescue error("Could not chown #{log} to #{user}")
end

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



46
47
48
# File 'lib/foreman/export/runitu.rb', line 46

def export_template(name, file = nil, template_root = nil)
  File.read(name)
end