Module: ForemanDebian::EngineHelper

Included in:
Initd::Engine, Monit::Engine
Defined in:
lib/foreman_debian/engine_helper.rb

Instance Method Summary collapse

Instance Method Details

#cleanupObject



14
15
16
17
18
19
20
21
# File 'lib/foreman_debian/engine_helper.rb', line 14

def cleanup
  threads = []
  each_file do |path|
    next if @exported.include? path
    threads << Thread.new { remove_file path }
  end
  ThreadsWait.all_waits(*threads)
end

#each_file(&block) ⇒ Object



40
41
42
43
44
# File 'lib/foreman_debian/engine_helper.rb', line 40

def each_file(&block)
  get_files.each do |path|
    block.call(path)
  end
end

#exec_command(command) ⇒ Object



46
47
48
49
50
51
52
53
54
# File 'lib/foreman_debian/engine_helper.rb', line 46

def exec_command(command)
  Open3.popen3(command) do |i, o, e, w|
    i.close
    out, err, wait = o.read, e.read, w
    status = wait ? wait.value : $?
    raise "Command `#{command}` failed: #{err}" unless status.success?
    out
  end
end

#export_file(path) ⇒ Object



23
24
25
26
# File 'lib/foreman_debian/engine_helper.rb', line 23

def export_file(path)
  @exported.push(path)
  @output.info " create  #{path.to_s} "
end

#get_filesObject



33
34
35
36
37
38
# File 'lib/foreman_debian/engine_helper.rb', line 33

def get_files
  paths = Pathname.glob(@export_path.join("#{@app}-*"))
  paths.select do |path|
    path.read.match(/# Autogenerated by foreman/)
  end
end

#pidfile(name) ⇒ Object



9
10
11
12
# File 'lib/foreman_debian/engine_helper.rb', line 9

def pidfile(name)
  name = "#{@app}-#{name}"
  Pathname.new('/var/run').join(name).join(name + '.pid')
end

#remove_file(path) ⇒ Object



28
29
30
31
# File 'lib/foreman_debian/engine_helper.rb', line 28

def remove_file(path)
  File.unlink path
  @output.info " remove  #{path.to_s}"
end

#setupObject



4
5
6
7
# File 'lib/foreman_debian/engine_helper.rb', line 4

def setup
  @exported = []
  @output = ForemanDebian::logger
end