Sha256: 3b4938498abaf72966fab8f02619bf3f265e5de919dd90a4146112bf6e036e74

Contents?: true

Size: 1.34 KB

Versions: 4

Compression:

Stored size: 1.34 KB

Contents

require "erb"
require "foreman/export/base"

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}"

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

    concurrency = parse_concurrency(options[:concurrency])

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

    process_template = export_template("upstart/process.conf.erb")

    engine.processes.values.each do |process|
      process_master_template = export_template("upstart/process_master.conf.erb")
      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 = port_for(options[:port], process.name, num)
        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

4 entries across 4 versions & 1 rubygems

Version Path
foreman-0.7.0 lib/foreman/export/upstart.rb
foreman-0.6.0 lib/foreman/export/upstart.rb
foreman-0.5.1 lib/foreman/export/upstart.rb
foreman-0.5.0 lib/foreman/export/upstart.rb