Class: Sensu::API::Process
- Inherits:
-
Object
- Object
- Sensu::API::Process
- Includes:
- Daemon
- Defined in:
- lib/sensu/api/process.rb
Constant Summary
Constants included from Utilities
Instance Attribute Summary
Attributes included from Daemon
Class Method Summary collapse
-
.run(options = {}) ⇒ Object
Create an instance of the Sensu API process, setup the Redis and Transport connections, start the API HTTP server, set up API process signal traps (for stopping), within the EventMachine event loop.
-
.test(options = {}) ⇒ Object
Create an instance of the Sensu API with initialized connections for running test specs.
Instance Method Summary collapse
-
#start ⇒ Object
Start the Sensu API HTTP server.
-
#start_http_server(bind, port) ⇒ Object
Start the API HTTP server.
-
#stop ⇒ Object
Stop the Sensu API process.
Methods included from Daemon
#initialize, #load_extensions, #load_settings, #log_notices, #pause, #print_settings!, #resume, #setup_logger, #setup_process, #setup_redis, #setup_signal_traps, #setup_spawn, #setup_transport, #validate_settings!
Methods included from Utilities
#attributes_match?, #check_subdued?, #deep_merge, #determine_check_cron_time, #eval_attribute_value, #find_attribute_value, #in_time_window?, #in_time_windows?, #object_substitute_tokens, #process_cpu_times, #process_eval_string, #random_uuid, #redact_sensitive, #retry_until_true, #substitute_tokens, #system_address, #system_hostname, #testing?
Class Method Details
.run(options = {}) ⇒ Object
Create an instance of the Sensu API process, setup the Redis and Transport connections, start the API HTTP server, set up API process signal traps (for stopping), within the EventMachine event loop.
15 16 17 18 19 20 21 22 23 |
# File 'lib/sensu/api/process.rb', line 15 def self.run(={}) api = self.new() EM::run do api.setup_redis api.setup_transport api.start api.setup_signal_traps end end |
.test(options = {}) ⇒ Object
Create an instance of the Sensu API with initialized connections for running test specs.
68 69 70 71 72 73 74 75 76 |
# File 'lib/sensu/api/process.rb', line 68 def self.test(={}) api = self.new() api.setup_redis do api.setup_transport do api.start yield end end end |
Instance Method Details
#start ⇒ Object
Start the Sensu API HTTP server. This method sets the service state to ‘:running`.
45 46 47 48 49 50 51 |
# File 'lib/sensu/api/process.rb', line 45 def start api = @settings[:api] || {} bind = api[:bind] || "0.0.0.0" port = api[:port] || 4567 start_http_server(bind, port) super end |
#start_http_server(bind, port) ⇒ Object
Start the API HTTP server. This method sets ‘@http_server`.
29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/sensu/api/process.rb', line 29 def start_http_server(bind, port) @logger.info("api listening", { :protocol => "http", :bind => bind, :port => port }) @http_server = EM::start_server(bind, port, HTTPHandler) do |handler| handler.logger = @logger handler.settings = @settings handler.redis = @redis handler.transport = @transport end end |
#stop ⇒ Object
Stop the Sensu API process. This method stops the HTTP server, closes the Redis and transport connections, sets the service state to ‘:stopped`, and stops the EventMachine event loop.
56 57 58 59 60 61 62 |
# File 'lib/sensu/api/process.rb', line 56 def stop @logger.warn("stopping") EM::stop_server(@http_server) @redis.close if @redis @transport.close if @transport super end |