Class: Foreman::Export::Inittab

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

Instance Attribute Summary

Attributes inherited from Base

#engine, #formation, #location, #options, #port

Instance Method Summary collapse

Methods inherited from Base

#app, #initialize, #log, procfile, #run, #template, #user

Constructor Details

This class inherits a constructor from Foreman::Export::Base

Instance Method Details

#exportObject



5
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
# File 'lib/foreman/export/inittab.rb', line 5

def export
  error("Must specify a location") unless location

  inittab = []
  inittab << "# ----- foreman #{app} processes -----"

  index = 1
  engine.each_process do |name, process|
    1.upto(engine.formation[name]) do |num|
      id = app.slice(0, 2).upcase + sprintf("%02d", index)
      port = engine.port_for(process, num)

      commands = []
      commands << "cd #{engine.root}"
      commands << "export PORT=#{port}"
      engine.env.each_pair do |var, env|
        commands << "export #{var.upcase}=#{shell_quote(env)}"
      end
      commands << "#{process.command} >> #{log}/#{name}-#{num}.log 2>&1"

      inittab << "#{id}:4:respawn:/bin/su - #{user} -c '#{commands.join(";")}'"
      index += 1
    end
  end

  inittab << "# ----- end foreman #{app} processes -----"

  inittab = inittab.join("\n") + "\n"

  if location == "-"
    puts inittab
  else
    say "writing: #{location}"
    File.open(location, "w") { |file| file.puts inittab }
  end
end