Class: Sensu::API::Process

Inherits:
Sinatra::Base
  • Object
show all
Extended by:
Daemon
Defined in:
lib/sensu/api/process.rb

Instance Attribute Summary

Attributes included from Daemon

#start_time

Class Method Summary collapse

Methods included from Daemon

initialize, load_extensions, load_settings, log_concerns, pause, resume, setup_logger, setup_process, setup_redis, setup_signal_traps, setup_transport, start, stop

Methods included from Utilities

#deep_merge, #random_uuid, #redact_sensitive, #retry_until_true, #testing?

Class Method Details

.bootstrap(options) ⇒ Object



39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
# File 'lib/sensu/api/process.rb', line 39

def bootstrap(options)
  setup_logger(options)
  set :logger, @logger
  load_settings(options)
  set :api, @settings[:api] || {}
  set :checks, @settings[:checks]
  set :all_checks, @settings.checks
  set :cors, @settings[:cors] || {
    "Origin" => "*",
    "Methods" => "GET, POST, PUT, DELETE, OPTIONS",
    "Credentials" => "true",
    "Headers" => "Origin, X-Requested-With, Content-Type, Accept, Authorization"
  }
  on_reactor_run
  self
end

.on_reactor_runObject



30
31
32
33
34
35
36
37
# File 'lib/sensu/api/process.rb', line 30

def on_reactor_run
  EM::next_tick do
    setup_redis
    set :redis, @redis
    setup_transport
    set :transport, @transport
  end
end

.run(options = {}) ⇒ Object



21
22
23
24
25
26
27
28
# File 'lib/sensu/api/process.rb', line 21

def run(options={})
  bootstrap(options)
  setup_process(options)
  EM::run do
    start
    setup_signal_traps
  end
end

.startObject



78
79
80
81
# File 'lib/sensu/api/process.rb', line 78

def start
  start_server
  super
end

.start_serverObject



56
57
58
59
60
61
62
63
64
65
66
# File 'lib/sensu/api/process.rb', line 56

def start_server
  Thin::Logging.silent = true
  bind = settings.api[:bind] || "0.0.0.0"
  port = settings.api[:port] || 4567
  @logger.info("api listening", {
    :bind => bind,
    :port => port
  })
  @thin = Thin::Server.new(bind, port, self)
  @thin.start
end

.stopObject



83
84
85
86
87
88
89
90
# File 'lib/sensu/api/process.rb', line 83

def stop
  @logger.warn("stopping")
  stop_server do
    @redis.close
    @transport.close
    super
  end
end

.stop_server(&callback) ⇒ Object



68
69
70
71
72
73
74
75
76
# File 'lib/sensu/api/process.rb', line 68

def stop_server(&callback)
  @thin.stop
  retry_until_true do
    unless @thin.running?
      callback.call
      true
    end
  end
end

.test(options = {}) ⇒ Object



92
93
94
95
# File 'lib/sensu/api/process.rb', line 92

def test(options={})
  bootstrap(options)
  start
end