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
Daemonize the current process
# 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
# 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
Starts the main loop, before calling this you should initialize the MCollective::Config singleton.
# File lib/mcollective/runner.rb, line 46 46: def run 47: Util.subscribe(Util.make_subscriptions("mcollective", :broadcast)) 48: Util.subscribe(Util.make_subscriptions("mcollective", :directed)) if @config.direct_addressing 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: request = receive 60: 61: if request.agent == "mcollective" 62: controlmsg(request) 63: else 64: agentmsg(request) 65: end 66: rescue Interrupt 67: Log.warn("Exiting after interrupt signal") 68: @connection.disconnect 69: exit! 70: 71: rescue MsgTTLExpired => e 72: Log.warn(e) 73: 74: rescue NotTargettedAtUs => e 75: Log.debug("Message does not pass filters, ignoring") 76: 77: rescue Exception => e 78: Log.warn("Failed to handle message: #{e} - #{e.class}\n") 79: Log.warn(e.backtrace.join("\n\t")) 80: end 81: end 82: end