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 def initialize(configfile) @config = Config.instance @config.loadconfig(configfile) unless @config.configured @config.mode = :server @state = :running @stats = PluginManager["global_stats"] @security = PluginManager["security_plugin"] @security.initiated_by = :node @connection = PluginManager["connector_plugin"] @connection.connect @agents = Agents.new unless Util.windows? Signal.trap("USR1") do Log.info("Reloading all agents after receiving USR1 signal") @agents.loadagents end Signal.trap("USR2") do Log.info("Cycling logging level due to USR2 signal") Log.cycle_level end else Util.setup_windows_sleeper end end
Starts the main loop, before calling this you should initialize the MCollective::Config singleton.
# File lib/mcollective/runner.rb, line 37 def run Data.load_data_sources Util.subscribe(Util.make_subscriptions("mcollective", :broadcast)) Util.subscribe(Util.make_subscriptions("mcollective", :directed)) if @config.direct_addressing # Start the registration plugin if interval isn't 0 begin PluginManager["registration_plugin"].run(@connection) unless @config.registerinterval == 0 rescue Exception => e Log.error("Failed to start registration plugin: #{e}") end loop do begin request = receive unless request.agent == "mcollective" agentmsg(request) else Log.error("Received a control message, possibly via 'mco controller' but this has been deprecated") end rescue SignalException => e Log.warn("Exiting after signal: #{e}") @connection.disconnect raise rescue MsgTTLExpired => e Log.warn(e) rescue NotTargettedAtUs => e Log.debug("Message does not pass filters, ignoring") rescue Exception => e Log.warn("Failed to handle message: #{e} - #{e.class}\n") Log.warn(e.backtrace.join("\n\t")) end return if @state == :stopping end end
Flag the runner to stop
# File lib/mcollective/runner.rb, line 80 def stop @state = :stopping end