Sha256: 720781155aad54879b1d3d32d4c5e7e707f91cc1f0082624944a9a81fd908007

Contents?: true

Size: 1.08 KB

Versions: 6

Compression:

Stored size: 1.08 KB

Contents

require "foreman/export/base"

class Foreman::Export::Inittab < Foreman::Export::Base

  def export(fname=nil, options={})
    app = options[:app] || File.basename(engine.directory)
    user = options[:user] || app
    log_root = options[:log] || "/var/log/#{app}"

    concurrency = Foreman::Utils.parse_concurrency(options[:concurrency])

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

    engine.processes.values.inject(1) do |index, process|
      1.upto(concurrency[process.name]) do |num|
        id = app.slice(0, 2).upcase + sprintf("%02d", index)
        port = engine.port_for(process, num, options[: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 fname
      FileUtils.mkdir_p(log_root)
      FileUtils.chown(user, nil, log_root)
      write_file(fname, inittab)
    else
      puts inittab
    end
  end

end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
foreman-0.8.0 lib/foreman/export/inittab.rb
foreman-0.7.5 lib/foreman/export/inittab.rb
foreman-0.7.4 lib/foreman/export/inittab.rb
foreman-0.7.3 lib/foreman/export/inittab.rb
foreman-0.7.2 lib/foreman/export/inittab.rb
foreman-0.7.1 lib/foreman/export/inittab.rb