Class: ForemanMonit::Exporter

Inherits:
Object
  • Object
show all
Defined in:
lib/foreman-monit/exporter.rb

Instance Method Summary collapse

Constructor Details

#initialize(options) ⇒ Exporter



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
# File 'lib/foreman-monit/exporter.rb', line 6

def initialize(options)
  @app = options[:app]
  @user = options[:user]
  @target = options[:target]
  @env = options[:env]
  @chruby = options[:chruby]
  @procfile = options[:procfile]

  @su = which_su
  @bash = which_bash

  @engine = Foreman::Engine.new
  load_procfile
  load_env
  @port = @engine.base_port
end

Instance Method Details

#base_dirObject



49
50
51
# File 'lib/foreman-monit/exporter.rb', line 49

def base_dir
  Dir.getwd
end

#chruby_initObject



41
42
43
44
45
46
47
# File 'lib/foreman-monit/exporter.rb', line 41

def chruby_init
  if @chruby
    "chruby #{@chruby} &&"
  else
    ''
  end
end

#infoObject



32
33
34
# File 'lib/foreman-monit/exporter.rb', line 32

def info
  puts @engine.processes.inspect
end

#log_file(name) ⇒ Object



57
58
59
# File 'lib/foreman-monit/exporter.rb', line 57

def log_file(name)
  File.expand_path(File.join(@target, "#{@app}-#{name}.log"))
end

#pid_file(name) ⇒ Object



53
54
55
# File 'lib/foreman-monit/exporter.rb', line 53

def pid_file(name)
  File.expand_path(File.join(@target, "#{@app}-#{name}.pid"))
end

#portObject



36
37
38
39
# File 'lib/foreman-monit/exporter.rb', line 36

def port
  @port += 1
  @port-1
end

#rails_envObject



61
62
63
# File 'lib/foreman-monit/exporter.rb', line 61

def rails_env
  @env
end

#run!Object



23
24
25
26
27
28
29
30
# File 'lib/foreman-monit/exporter.rb', line 23

def run!
  Dir.mkdir(@target) unless File.exist?(@target)
  FileUtils.rm Dir.glob("#{@target}/*.conf")
  @engine.each_process do |name, process|
    file_name = File.join(@target, "#{@app}-#{name}.conf")
    File.open(file_name, 'w') { |f| f.write ERB.new(File.read(File.expand_path('../../../templates/monitrc.erb', __FILE__))).result(binding) }
  end
end