Class: Foreman::Configuration
- Inherits:
-
Object
- Object
- Foreman::Configuration
- Defined in:
- lib/foreman/configuration.rb
Instance Attribute Summary collapse
-
#app ⇒ Object
readonly
Returns the value of attribute app.
-
#processes ⇒ Object
readonly
Returns the value of attribute processes.
Instance Method Summary collapse
-
#initialize(app) ⇒ Configuration
constructor
A new instance of Configuration.
- #scale(process, amount) ⇒ Object
- #write ⇒ Object
Constructor Details
#initialize(app) ⇒ Configuration
Returns a new instance of Configuration.
8 9 10 11 12 |
# File 'lib/foreman/configuration.rb', line 8 def initialize(app) @app = app @processes = {} read_initial_config end |
Instance Attribute Details
#app ⇒ Object (readonly)
Returns the value of attribute app.
5 6 7 |
# File 'lib/foreman/configuration.rb', line 5 def app @app end |
#processes ⇒ Object (readonly)
Returns the value of attribute processes.
6 7 8 |
# File 'lib/foreman/configuration.rb', line 6 def processes @processes end |
Instance Method Details
#scale(process, amount) ⇒ Object
14 15 16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/foreman/configuration.rb', line 14 def scale(process, amount) old_amount = processes[process].to_i processes[process] = amount.to_i amount = amount.to_i if (old_amount < amount) ((old_amount + 1) .. amount).each { |num| run "start #{app}-#{process} NUM=#{num}" } elsif (amount < old_amount) ((amount + 1) .. old_amount).each { |num| run "stop #{app}-#{process} NUM=#{num}" } end write end |
#write ⇒ Object
28 29 30 31 32 33 |
# File 'lib/foreman/configuration.rb', line 28 def write write_file "/etc/foreman/#{app}.conf", <<-UPSTART_CONFIG #{app}_processes="#{processes.keys.join(' ')}" #{processes.keys.map { |k| "#{app}_#{k}=\"#{processes[k]}\"" }.join("\n")} UPSTART_CONFIG end |