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, print_settings, resume, setup_logger, setup_process, setup_redis, setup_signal_traps, setup_transport, start, stop

Methods included from Utilities

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

Class Method Details

.bootstrap(options) ⇒ Object



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

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"
  }
end

.run(options = {}) ⇒ Object



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

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

.setup_connectionsObject



32
33
34
35
36
37
38
39
40
# File 'lib/sensu/api/process.rb', line 32

def setup_connections
  setup_redis do |redis|
    set :redis, redis
    setup_transport do |transport|
      set :transport, transport
      yield if block_given?
    end
  end
end

.startObject



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

def start
  start_server
  super
end

.start_serverObject



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

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



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

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

.stop_serverObject



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

def stop_server
  @thin.stop
  retry_until_true do
    unless @thin.running?
      yield
      true
    end
  end
end

.test(options = {}) ⇒ Object



93
94
95
96
97
98
99
# File 'lib/sensu/api/process.rb', line 93

def test(options={})
  bootstrap(options)
  setup_connections do
    start
    yield
  end
end