Class: Chef::Handler::SpinupComplete

Inherits:
Chef::Handler show all
Defined in:
lib/chef-handler-spinup-complete.rb

Instance Method Summary collapse

Constructor Details

#initialize(opts = {}) ⇒ SpinupComplete

Returns a new instance of SpinupComplete.



32
33
34
# File 'lib/chef-handler-spinup-complete.rb', line 32

def initialize(opts={})
  @handlers = opts.fetch(:handlers, ['default'])
end

Instance Method Details

#reportObject



36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/chef-handler-spinup-complete.rb', line 36

def report
  # This sleep is to avoid Sensu client having been restarted as the last
  # notification of the Chef run and this handler running immediately
  # during the reporting phase. In that case, the handler will run too
  # quickly and get a ECONNREFUSED.
  sleep(1)
  begin
    sock = TCPSocket.new('127.0.0.1', 3030)
    sock.write(warn_first)
    sock.write(ok_second)
    sock.close
  rescue Errno::ECONNREFUSED
    Chef::Log.error("Couldn't write to the Sensu client socket")
  end
end