Class | MCollective::Runner |
In: |
lib/mcollective/runner.rb
|
Parent: | Object |
The main runner for the daemon, supports running in the foreground and the background, keeps detailed stats and provides hooks to access all this information
# File lib/mcollective/runner.rb, line 6 6: def initialize(configfile) 7: @config = Config.instance 8: @config.loadconfig(configfile) unless @config.configured 9: 10: @stats = PluginManager["global_stats"] 11: 12: @security = PluginManager["security_plugin"] 13: @security.initiated_by = :node 14: 15: @connection = PluginManager["connector_plugin"] 16: @connection.connect 17: 18: @agents = Agents.new 19: 20: unless Util.windows? 21: Signal.trap("USR1") do 22: Log.info("Reloading all agents after receiving USR1 signal") 23: @agents.loadagents 24: end 25: 26: Signal.trap("USR2") do 27: Log.info("Cycling logging level due to USR2 signal") 28: Log.cycle_level 29: end 30: else 31: Util.setup_windows_sleeper 32: end 33: end
Starts the main loop, before calling this you should initialize the MCollective::Config singleton.
# File lib/mcollective/runner.rb, line 36 36: def run 37: Data.load_data_sources 38: 39: Util.subscribe(Util.make_subscriptions("mcollective", :broadcast)) 40: Util.subscribe(Util.make_subscriptions("mcollective", :directed)) if @config.direct_addressing 41: 42: # Start the registration plugin if interval isn't 0 43: begin 44: PluginManager["registration_plugin"].run(@connection) unless @config.registerinterval == 0 45: rescue Exception => e 46: Log.error("Failed to start registration plugin: #{e}") 47: end 48: 49: loop do 50: begin 51: request = receive 52: 53: unless request.agent == "mcollective" 54: agentmsg(request) 55: else 56: Log.error("Received a control message, possibly via 'mco controller' but this has been deprecated") 57: end 58: rescue SignalException => e 59: Log.warn("Exiting after signal: #{e}") 60: @connection.disconnect 61: raise 62: 63: rescue MsgTTLExpired => e 64: Log.warn(e) 65: 66: rescue NotTargettedAtUs => e 67: Log.debug("Message does not pass filters, ignoring") 68: 69: rescue Exception => e 70: Log.warn("Failed to handle message: #{e} - #{e.class}\n") 71: Log.warn(e.backtrace.join("\n\t")) 72: end 73: end 74: end