Class: ForemanDebian::Monit::Engine

Inherits:
Object
  • Object
show all
Includes:
EngineHelper
Defined in:
lib/foreman_debian/monit/engine.rb

Instance Method Summary collapse

Methods included from EngineHelper

#cleanup, #each_file, #exec_command, #export_file, #pidfile, #remove_file, #setup

Constructor Details

#initialize(app, export_path = nil) ⇒ Engine

Returns a new instance of Engine.



7
8
9
10
11
# File 'lib/foreman_debian/monit/engine.rb', line 7

def initialize(app, export_path = nil)
  @app = app
  @export_path = Pathname.new(export_path || '/etc/monit/conf.d')
  setup
end

Instance Method Details

#install(name, script) ⇒ Object



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/foreman_debian/monit/engine.rb', line 13

def install(name, script)
  name = "#{@app}-#{name}"

  FileUtils.mkdir_p(@export_path)
  template = Template.new('monit_config')
  output = template.render({
                               :app => @app,
                               :name => name,
                               :script_pidfile => script.pidfile,
                               :script_path => script.path,
                           })
  config_path = @export_path.join(name)
  File.open(config_path, 'w') do |file|
    file.puts(output)
    export_file(config_path)
  end
end