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