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

daemonize   new   run  

Public Class methods

Daemonize the current process

[Source]

    # File lib/mcollective/runner.rb, line 32
32:         def self.daemonize
33:             fork do
34:                 Process.setsid
35:                 exit if fork
36:                 Dir.chdir('/tmp')
37:                 STDIN.reopen('/dev/null')
38:                 STDOUT.reopen('/dev/null', 'a')
39:                 STDERR.reopen('/dev/null', 'a')
40: 
41:                 yield
42:             end
43:         end

[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:             Signal.trap("USR1") do
21:                 Log.info("Reloading all agents after receiving USR1 signal")
22:                 @agents.loadagents
23:             end
24: 
25:             Signal.trap("USR2") do
26:                 Log.info("Cycling logging level due to USR2 signal")
27:                 Log.cycle_level
28:             end
29:         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 46
46:         def run
47:             Util.subscribe(Util.make_subscriptions("mcollective", :broadcast))
48: 
49:             # Start the registration plugin if interval isn't 0
50:             begin
51:                 PluginManager["registration_plugin"].run(@connection) unless @config.registerinterval == 0
52:             rescue Exception => e
53:                 Log.error("Failed to start registration plugin: #{e}")
54:             end
55: 
56:             loop do
57:                 begin
58:                     msg = receive
59: 
60:                     collective = msg[:collective]
61:                     agent = msg[:agent]
62: 
63:                     # requests from older clients would not include the
64:                     # :collective and :agent this parses the target in
65:                     # a backward compat way for them
66:                     unless collective && agent
67:                         parsed_dest = Util.parse_msgtarget(msg[:msgtarget])
68:                         collective = parsed_dest[:collective]
69:                         agent = parsed_dest[:agent]
70:                     end
71: 
72:                     if agent == "mcollective"
73:                         Log.debug("Handling message for mcollectived controller")
74: 
75:                         controlmsg(msg, collective)
76:                     else
77:                         Log.debug("Handling message for agent '#{agent}' on collective '#{collective}'")
78: 
79:                         agentmsg(msg, agent, collective)
80:                     end
81:                 rescue Interrupt
82:                     Log.warn("Exiting after interrupt signal")
83:                     @connection.disconnect
84:                     exit!
85: 
86:                 rescue NotTargettedAtUs => e
87:                     Log.debug("Message does not pass filters, ignoring")
88: 
89:                 rescue Exception => e
90:                     Log.warn("Failed to handle message: #{e} - #{e.class}\n")
91:                     Log.warn(e.backtrace.join("\n\t"))
92:                 end
93:             end
94:         end

[Validate]