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

Methods

new   run  

Public Class methods

[Source]

    # 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

Public Instance methods

Starts the main loop, before calling this you should initialize the MCollective::Config singleton.

[Source]

    # File lib/mcollective/runner.rb, line 36
36:     def run
37:       Util.subscribe(Util.make_subscriptions("mcollective", :broadcast))
38:       Util.subscribe(Util.make_subscriptions("mcollective", :directed)) if @config.direct_addressing
39: 
40:       # Start the registration plugin if interval isn't 0
41:       begin
42:         PluginManager["registration_plugin"].run(@connection) unless @config.registerinterval == 0
43:       rescue Exception => e
44:         Log.error("Failed to start registration plugin: #{e}")
45:       end
46: 
47:       loop do
48:         begin
49:           request = receive
50: 
51:           if request.agent == "mcollective"
52:             controlmsg(request)
53:           else
54:             agentmsg(request)
55:           end
56:         rescue SignalException => e
57:           Log.warn("Exiting after signal: #{e}")
58:           @connection.disconnect
59:           raise
60: 
61:         rescue MsgTTLExpired => e
62:           Log.warn(e)
63: 
64:         rescue NotTargettedAtUs => e
65:           Log.debug("Message does not pass filters, ignoring")
66: 
67:         rescue Exception => e
68:           Log.warn("Failed to handle message: #{e} - #{e.class}\n")
69:           Log.warn(e.backtrace.join("\n\t"))
70:         end
71:       end
72:     end

[Validate]