Module: Bixby::Agent::Config::ClassMethods
- Defined in:
- lib/bixby-agent/agent/config.rb
Instance Method Summary collapse
- #bad_config(ex = nil) ⇒ Object
- #config_dir ⇒ Object
- #config_file ⇒ Object
- #load_config(root_dir) ⇒ Object
Instance Method Details
#bad_config(ex = nil) ⇒ Object
56 57 58 59 60 61 62 |
# File 'lib/bixby-agent/agent/config.rb', line 56 def bad_config(ex = nil) # TODO should force a reinstall/handshake? $stderr.puts "error loading config from #{config_file}" $stderr.puts "(#{ex})" if ex $stderr.puts "exiting" exit 1 end |
#config_dir ⇒ Object
14 15 16 |
# File 'lib/bixby-agent/agent/config.rb', line 14 def config_dir Bixby.path("etc") end |
#config_file ⇒ Object
18 19 20 |
# File 'lib/bixby-agent/agent/config.rb', line 18 def config_file File.join(config_dir, "bixby.yml") end |
#load_config(root_dir) ⇒ Object
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 |
# File 'lib/bixby-agent/agent/config.rb', line 22 def load_config(root_dir) # make sure BIXBY_HOME is set correctly ENV["BIXBY_HOME"] = File.(root_dir || ENV["BIXBY_HOME"] || Agent::DEFAULT_ROOT_DIR) return nil if not File.exists? config_file # load it! begin config = YAML.load_file(config_file) if not config.kind_of? Hash or config.empty? then bad_config("corrupted file contents") end log_level = config["log_level"] log_level = log_level.strip.downcase if log_level.kind_of? String Bixby::Log.setup_logger(:level => log_level) agent = Agent.allocate KEYS.each do |k| m = "#{k}=".to_sym agent.send(m, config[k]) if agent.respond_to? m end agent.new = false return agent rescue Exception => ex if ex.kind_of? SystemExit then raise ex end bad_config(ex) if ex. != "exit" end end |