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:             controltopic = Util.make_target("mcollective", :command)
48:             @connection.subscribe(controltopic)
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:                     dest = msg[:msgtarget]
61: 
62:                     if dest =~ /#{controltopic}/
63:                         Log.debug("Handling message for mcollectived controller")
64: 
65:                         controlmsg(msg)
66:                     elsif dest =~ /#{@config.topicprefix}#{@config.topicsep}(.+)#{@config.topicsep}command/
67:                         target = $1
68: 
69:                         Log.debug("Handling message for #{target}")
70: 
71:                         agentmsg(msg, target)
72:                     end
73:                 rescue Interrupt
74:                     Log.warn("Exiting after interrupt signal")
75:                     @connection.disconnect
76:                     exit!
77: 
78:                 rescue NotTargettedAtUs => e
79:                     Log.debug("Message does not pass filters, ignoring")
80: 
81:                 rescue Exception => e
82:                     Log.warn("Failed to handle message: #{e} - #{e.class}\n")
83:                     Log.warn(e.backtrace.join("\n\t"))
84:                 end
85:             end
86:         end

[Validate]