Class: Foreman::Export::UpstartUser

Inherits:
Upstart
  • Object
show all
Defined in:
lib/foreman/export/upstart_user.rb

Instance Method Summary collapse

Constructor Details

#initialize(location, engine, options = {}) ⇒ UpstartUser

Returns a new instance of UpstartUser.



5
6
7
8
9
10
11
12
13
# File 'lib/foreman/export/upstart_user.rb', line 5

def initialize location, engine, options={}
  super
  # what a pain in the ass
  # template is obviously not intended to be overriden
  unless @options.has_key?(:template)
    template = File.expand_path("../../../../data/export/upstart_user", __FILE__)
    @options = { :template => template }.merge(@options).freeze
  end
end

Instance Method Details

#appObject



39
40
41
# File 'lib/foreman/export/upstart_user.rb', line 39

def app
  options[:app] || File.basename(Dir.pwd)
end

#exportObject



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/foreman/export/upstart_user.rb', line 15

def export
  super

  Dir["#{location}/#{app}*.conf"].each do |file|
    clean file
  end

  write_template "upstart/master.conf.erb", "#{app}.conf", binding

  engine.each_process do |name, process|
    next if engine.formation[name] < 1
    write_template "upstart/process_master.conf.erb", "#{app}-#{name}.conf", binding

    1.upto(engine.formation[name]) do |num|
      port = engine.port_for(process, num)
      write_template "upstart_user/process.conf.erb", "#{app}-#{name}-#{num}.conf", binding
    end
  end
end

#locationObject



35
36
37
# File 'lib/foreman/export/upstart_user.rb', line 35

def location
  options[:location] || "/home/#{user}/.init"
end

#logObject



43
44
45
# File 'lib/foreman/export/upstart_user.rb', line 43

def log
  options[:log] || "log"
end

#userObject



47
48
49
# File 'lib/foreman/export/upstart_user.rb', line 47

def user
  options[:user] || `whoami`.strip
end