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

[Validate]