Class: Foreman::Export::Upstart
- Inherits:
-
Object
- Object
- Foreman::Export::Upstart
- Defined in:
- lib/foreman/export/upstart.rb
Instance Attribute Summary collapse
-
#engine ⇒ Object
readonly
Returns the value of attribute engine.
Instance Method Summary collapse
- #export(app) ⇒ Object
-
#initialize(engine) ⇒ Upstart
constructor
A new instance of Upstart.
Constructor Details
#initialize(engine) ⇒ Upstart
Returns a new instance of Upstart.
8 9 10 |
# File 'lib/foreman/export/upstart.rb', line 8 def initialize(engine) @engine = engine end |
Instance Attribute Details
#engine ⇒ Object (readonly)
Returns the value of attribute engine.
6 7 8 |
# File 'lib/foreman/export/upstart.rb', line 6 def engine @engine end |
Instance Method Details
#export(app) ⇒ Object
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 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/foreman/export/upstart.rb', line 12 def export(app) FileUtils.mkdir_p "/etc/foreman" FileUtils.mkdir_p "/etc/init" config = Foreman::Configuration.new(app) write_file "/etc/init/#{app}.conf", <<-UPSTART_MASTER pre-start script bash << "EOF" mkdir -p /var/log/#{app} if [ -f /etc/foreman/#{app}.conf ]; then source /etc/foreman/#{app}.conf fi for process in $( echo "$#{app}_processes" ); do process_count_config="#{app}_$process" process_count=${!process_count_config} for ((i=1; i<=${process_count:=1}; i+=1)); do start #{app}-$process NUM=$i done done EOF end script UPSTART_MASTER engine.processes.values.each do |process| write_file "/etc/init/#{app}-#{process.name}.conf", <<-UPSTART_CHILD instance $NUM stop on stopping #{app} respawn chdir #{engine.directory} exec #{process.command} >>/var/log/#{app}/#{process.name}.log 2>&1 UPSTART_CHILD end engine.processes.each do |name, process| config.processes[name] ||= 1 end config.write end |