Class: Custodian::CLI

Inherits:
Object
  • Object
show all
Defined in:
lib/custodian/cli.rb

Overview

The CLI class encapsulates Custodian’s command-line interface.

Constant Summary collapse

DEFAULT_PORT =
5100

Instance Method Summary collapse

Constructor Details

#initialize(arguments) ⇒ CLI

Create a new command-line interface.

arguments - An Array of String objects describing arguments

passed to the program (see CLI#parse).


16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
# File 'lib/custodian/cli.rb', line 16

def initialize(arguments)
  options = parse arguments

  if samplers = options[:samplers]
    load_samplers samplers
  end

  if options.include? :daemonize
    deamonize
  end

  if pidfile = options[:pidfile]
    write_pidfile pidfile
  end

  log "Custodian is accepting connections on port #{options[:port]}"

  compatible_samplers   = Custodian::Samplers.compatible
  incompatible_samplers = Custodian::Samplers.incompatible

  log "#{compatible_samplers.count} compatible samplers."
  compatible_samplers.each do |s|
    log "   - #{s.description}"
  end

  log "#{incompatible_samplers.count} incompatible samplers."
  incompatible_samplers.each do |s|
    log "   - #{s.description}"
  end

  log "CTRL+C to stop"

  Thin::Logging.silent = true
  Thin::Server.start '0.0.0.0', options[:port] do
    use Rack::CommonLogger
    use Rack::ShowExceptions
    use Rack::Auth::Basic do |username, password|
      [username, password] == [options[:username], options[:password]]
    end if options.include? :username

    run Custodian::API.new
  end
end