Sha256: e8c968dd52eb543a3ce402f42784ca2786c28321cd1eb605985329890aa26e43

Contents?: true

Size: 1.56 KB

Versions: 7

Compression:

Stored size: 1.56 KB

Contents

require "erb"
require "foreman/export"

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

  def export
    error("Must specify a location") unless location

    FileUtils.mkdir_p location

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

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

    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 = self.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(self.concurrency[process.name]) do |num|
        port = engine.port_for(process, num, self.port)
        process_config = ERB.new(process_template).result(binding)
        write_file "#{location}/#{app}-#{process.name}-#{num}.conf", process_config
      end
    end

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

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
foreman-0.47.0 lib/foreman/export/upstart.rb
foreman-0.46.0-mingw32 lib/foreman/export/upstart.rb
foreman-0.46.0-java lib/foreman/export/upstart.rb
foreman-0.46.0 lib/foreman/export/upstart.rb
foreman-0.45.0-mingw32 lib/foreman/export/upstart.rb
foreman-0.45.0-java lib/foreman/export/upstart.rb
foreman-0.45.0 lib/foreman/export/upstart.rb