Class: ProcfileUpstartExporter::Creator

Inherits:
Object
  • Object
show all
Defined in:
lib/procfile_upstart_exporter/creator.rb

Instance Method Summary collapse

Constructor Details

#initialize(procfile_parser = ProcfileUpstartExporter::ProcfileParser.new, environment_parser = ProcfileUpstartExporter::EnvironmentParser.new, process_job_renderer = ProcfileUpstartExporter::ProcessJobRenderer.new) ⇒ Creator

Returns a new instance of Creator.



2
3
4
5
6
7
8
9
10
# File 'lib/procfile_upstart_exporter/creator.rb', line 2

def initialize(
  procfile_parser      = ProcfileUpstartExporter::ProcfileParser.new,
  environment_parser   = ProcfileUpstartExporter::EnvironmentParser.new,
  process_job_renderer = ProcfileUpstartExporter::ProcessJobRenderer.new
)
  self.procfile_parser      = procfile_parser
  self.environment_parser   = environment_parser
  self.process_job_renderer = process_job_renderer
end

Instance Method Details

#create(application, procfile, log, environment, user, upstart_jobs_path, templates_path = File.expand_path('../../../templates', __FILE__)) ⇒ Object



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/procfile_upstart_exporter/creator.rb', line 12

def create(
  application, procfile, log, environment, user, upstart_jobs_path,
  templates_path = File.expand_path('../../../templates', __FILE__)
)
  ProcfileUpstartExporter.logger.debug 'Starting Upstart jobs creation ' \
                                       "for `#{ application }'"
  application_template = File.join templates_path, 'application.conf'
  application_job      = File.join upstart_jobs_path, "#{ application }.conf"
  application_path     = File.join upstart_jobs_path, application
  application_log_path = File.join log, application

  FileUtils.cp application_template, application_job
  FileUtils.mkdir_p application_path
  FileUtils.mkdir_p application_log_path
  FileUtils.chown user, user, application_log_path
  procfile_parser.parse(procfile).each do |process|
    File.write(
      File.join(application_path, "#{ process.name }.conf"),
      process_job_renderer.render(
        application, user, environment_parser.parse(environment),
        Dir.pwd, log, process
      )
    )
  end
  ProcfileUpstartExporter.logger.debug 'Created Upstart jobs for ' \
                                       "`#{ application }'"
end