Sha256: e00363f8f470a679378395ef476d03902a4651815a1e314a9b7993e4c0693642

Contents?: true

Size: 1.5 KB

Versions: 21

Compression:

Stored size: 1.5 KB

Contents

require "erb"
require "foreman/export"

class Foreman::Export::Upstart < Foreman::Export::Base

  def export(location, options={})
    error("Must specify a location") unless location

    FileUtils.mkdir_p location

    app = options[:app] || File.basename(engine.directory)
    user = options[:user] || app
    log_root = options[:log] || "/var/log/#{app}"
    template_root = options[:template]

    Dir["#{location}/#{app}*.conf"].each do |file|
      say "cleaning up: #{file}"
      FileUtils.rm(file)
    end

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

    master_template = export_template("upstart", "master.conf.erb", template_root)
    master_config   = ERB.new(master_template).result(binding)
    write_file "#{location}/#{app}.conf", master_config

    process_template = export_template("upstart", "process.conf.erb", template_root)

    engine.procfile.entries.each do |process|
      next if (conc = concurrency[process.name]) < 1
      process_master_template = export_template("upstart", "process_master.conf.erb", template_root)
      process_master_config   = ERB.new(process_master_template).result(binding)
      write_file "#{location}/#{app}-#{process.name}.conf", process_master_config

      1.upto(concurrency[process.name]) do |num|
        port = engine.port_for(process, num, options[:port])
        process_config = ERB.new(process_template).result(binding)
        write_file "#{location}/#{app}-#{process.name}-#{num}.conf", process_config
      end
    end
  end

end

Version data entries

21 entries across 21 versions & 1 rubygems

Version Path
foreman-0.37.0.pre3-mingw32 lib/foreman/export/upstart.rb
foreman-0.37.0.pre3-java lib/foreman/export/upstart.rb
foreman-0.37.0.pre3 lib/foreman/export/upstart.rb
foreman-0.37.0.pre2-java lib/foreman/export/upstart.rb
foreman-0.37.0.pre2 lib/foreman/export/upstart.rb
foreman-0.37.0.pre1-java lib/foreman/export/upstart.rb
foreman-0.37.0.pre1 lib/foreman/export/upstart.rb
foreman-0.36.1 lib/foreman/export/upstart.rb
foreman-0.36.0 lib/foreman/export/upstart.rb
foreman-0.35.0 lib/foreman/export/upstart.rb
foreman-0.34.1 lib/foreman/export/upstart.rb
foreman-0.34.0 lib/foreman/export/upstart.rb
foreman-0.33.1 lib/foreman/export/upstart.rb
foreman-0.33.0 lib/foreman/export/upstart.rb
foreman-0.32.0 lib/foreman/export/upstart.rb
foreman-0.31.0 lib/foreman/export/upstart.rb
foreman-0.30.1 lib/foreman/export/upstart.rb
foreman-0.30.0 lib/foreman/export/upstart.rb
foreman-0.29.0 lib/foreman/export/upstart.rb
foreman-0.28.0.pre2 lib/foreman/export/upstart.rb