lib/bmc-daemon-lib/conf.rb in bmc-daemon-lib-0.1.2 vs lib/bmc-daemon-lib/conf.rb in bmc-daemon-lib-0.2.0

- old
+ new

@@ -1,9 +1,11 @@ # FIXME: files named with hyphens will not be found by Chamber for now require "chamber" module BmcDaemonLib + # Class exceptions + class ConfigInitiRequired < StandardError; end class ConfigMissingParameter < StandardError; end class ConfigOtherError < StandardError; end class ConfigParseError < StandardError; end class ConfigMultipleGemspec < StandardError; end class ConfigMissingGemspec < StandardError; end @@ -51,12 +53,14 @@ fail ConfigMissingParameter, "gemspec: missing version" unless @app_ver # Now we know app_name, initalize app_libs @app_libs = File.expand_path("lib/#{@app_name}/", @app_root) + # By default, Newrelic is disabled + ENV["NEWRELIC_AGENT_ENABLED"] = "false" + # Add other config files - #add_default_config add_config generate(:config_defaults) add_config generate(:config_etc) # Return something return @app_name @@ -106,11 +110,11 @@ path.reduce(Conf) { |m, key| m && m[key.to_s] } end def self.newrelic_enabled? ensure_init - self[:newrelic] && self[:newrelic][:licence] + !! (self[:newrelic] && self[:newrelic][:license]) end # Defaults generators def self.generate what ensure_init @@ -154,25 +158,20 @@ @files << File.expand_path(path) if path && File.readable?(path) end def self.prepare_newrelic section, logfile # Disable NewRelic if no config present - unless self.newrelic_enabled? - ENV["NEWRELIC_AGENT_ENABLED"] = "false" - return - end + return unless self.newrelic_enabled? # Enable GC profiler GC::Profiler.enable - # Enable module - ENV["NEWRELIC_AGENT_ENABLED"] = "true" + # Set logfile, license, monitor mode + ENV["NEW_RELIC_LOG"] = logfile.to_s if logfile + ENV["NEW_RELIC_LICENSE_KEY"] = section[:license].to_s ENV["NEW_RELIC_MONITOR_MODE"] = "true" - # License - ENV["NEW_RELIC_LICENSE_KEY"] = section[:licence].to_s - # Build NewRelic app_name if not provided as-is if section[:app_name] ENV["NEW_RELIC_APP_NAME"] = section[:app_name].to_s else stack = [] @@ -181,21 +180,25 @@ stack << @app_env text = stack.join('-') ENV["NEW_RELIC_APP_NAME"] = "#{text}-#{host};#{text}" end - # Logfile - ENV["NEW_RELIC_LOG"] = logfile.to_s if logfile + # Enable module + ENV["NEWRELIC_AGENT_ENABLED"] = "true" end private def self.ensure_init - # Skip is already done - return if @initialized + unless @initialized + fail ConfigInitiRequired, "ensure_init: Conf.init(app_root) should be invoked beforehand" + end - # Go through init if not already done - self.init + # # Skip is already done + # return if @initialized + + # # Go through init if not already done + # self.init end end end