Class: Foreman::Export::Inittab
- Defined in:
- lib/foreman/export/inittab.rb
Instance Attribute Summary
Attributes inherited from Base
#app, #concurrency, #engine, #location, #log, #port, #template, #user
Instance Method Summary collapse
Methods inherited from Base
Constructor Details
This class inherits a constructor from Foreman::Export::Base
Instance Method Details
#export ⇒ Object
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 |
# File 'lib/foreman/export/inittab.rb', line 5 def export app = self.app || File.basename(engine.directory) user = self.user || app log_root = self.log || "/var/log/#{app}" inittab = [] inittab << "# ----- foreman #{app} processes -----" engine.procfile.entries.inject(1) do |index, process| 1.upto(self.concurrency[process.name]) do |num| id = app.slice(0, 2).upcase + sprintf("%02d", index) port = engine.port_for(process, num, self.port) inittab << "#{id}:4:respawn:/bin/su - #{user} -c 'PORT=#{port} #{process.command} >> #{log_root}/#{process.name}-#{num}.log 2>&1'" index += 1 end index end inittab << "# ----- end foreman #{app} processes -----" inittab = inittab.join("\n") + "\n" if location == "-" puts inittab else FileUtils.mkdir_p(log_root) rescue error "could not create #{log_root}" FileUtils.chown(user, nil, log_root) rescue error "could not chown #{log_root} to #{user}" write_file(location, inittab) end end |