Class: BigBrother::CLI

Inherits:
Rack::Server
  • Object
show all
Defined in:
lib/big_brother/cli.rb

Defined Under Namespace

Classes: Options

Instance Method Summary collapse

Constructor Details

#initialize(options = nil) ⇒ CLI

Returns a new instance of CLI.



40
41
42
# File 'lib/big_brother/cli.rb', line 40

def initialize(options = nil)
  super
end

Instance Method Details

#default_optionsObject



77
78
79
80
81
82
# File 'lib/big_brother/cli.rb', line 77

def default_options
  super.merge(
    :big_brother_config => '/etc/big_brother.conf',
    :config_dir => '/etc/big_brother'
  )
end

#opt_parserObject



44
45
46
# File 'lib/big_brother/cli.rb', line 44

def opt_parser
  Options.new
end

#startObject



48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
# File 'lib/big_brother/cli.rb', line 48

def start
  unless File.exists?(options[:big_brother_config])
    puts "Could not find #{options[:big_brother_config]}. Specify correct location with -c file"
    exit 1
  end

  BigBrother.logger.level = BigBrother::Logger::Level::DEBUG if options[:verbose]
  BigBrother.config_dir = options[:config_dir]

  Thin::Callbacks.after_connect do
    EM.syslog_setup('0.0.0.0', 514)
    BigBrother.logger.info "Starting big brother on port #{options[:Port]}"

    EM.synchrony do
      BigBrother.configure(options[:big_brother_config])
      BigBrother.start_ticker!
    end

    Signal.trap("HUP") do
      EM.synchrony do
        BigBrother.logger.info "HUP trapped. Reconfiguring big brother"
        BigBrother.reconfigure
      end
    end
  end

  super
end