Module: ForemanDebian::EngineHelper
- Included in:
- Initd::Engine, Monit::Engine
- Defined in:
- lib/foreman_debian/engine_helper.rb
Instance Method Summary collapse
- #cleanup ⇒ Object
- #each_file(&block) ⇒ Object
- #exec_command(command) ⇒ Object
- #export_file(path) ⇒ Object
- #pidfile(name) ⇒ Object
- #remove_file(path) ⇒ Object
- #setup ⇒ Object
Instance Method Details
#cleanup ⇒ Object
14 15 16 17 18 19 |
# File 'lib/foreman_debian/engine_helper.rb', line 14 def cleanup each_file do |path| next if @exported.include? path remove_file path end end |
#each_file(&block) ⇒ Object
31 32 33 34 35 36 37 |
# File 'lib/foreman_debian/engine_helper.rb', line 31 def each_file(&block) Dir.glob @export_path.join("#{@app}-*") do |path| path = Pathname.new(path) next unless path.read.match(/# Autogenerated by foreman/) block.call(path) end end |
#exec_command(command) ⇒ Object
39 40 41 42 43 44 45 46 47 |
# File 'lib/foreman_debian/engine_helper.rb', line 39 def exec_command(command) Open3.popen3(command) do |i, o, e, w| i.close out, err, wait = o.read, e.read, w s = wait ? wait.value : $? s.success? or raise "Command `#{command}` failed: #{err}" out end end |
#export_file(path) ⇒ Object
21 22 23 24 |
# File 'lib/foreman_debian/engine_helper.rb', line 21 def export_file(path) @exported.push(path) @output.info " create #{path.to_s} " 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
26 27 28 29 |
# File 'lib/foreman_debian/engine_helper.rb', line 26 def remove_file(path) File.unlink path @output.info " remove #{path.to_s}" end |
#setup ⇒ Object
4 5 6 7 |
# File 'lib/foreman_debian/engine_helper.rb', line 4 def setup @exported = [] @output = ForemanDebian::logger end |