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 34 34: def self.daemonize 35: fork do 36: Process.setsid 37: exit if fork 38: Dir.chdir('/tmp') 39: STDIN.reopen('/dev/null') 40: STDOUT.reopen('/dev/null', 'a') 41: STDERR.reopen('/dev/null', 'a') 42: 43: yield 44: end 45: 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: @log = Log.instance 11: 12: @stats = PluginManager["global_stats"] 13: 14: @security = PluginManager["security_plugin"] 15: @security.initiated_by = :node 16: 17: @connection = PluginManager["connector_plugin"] 18: @connection.connect 19: 20: @agents = Agents.new 21: 22: Signal.trap("USR1") do 23: @log.info("Reloading all agents after receiving USR1 signal") 24: @agents.loadagents 25: end 26: 27: Signal.trap("USR2") do 28: @log.info("Cycling logging level due to USR2 signal") 29: @log.cycle_level 30: end 31: end
Starts the main loop, before calling this you should initialize the MCollective::Config singleton.
# File lib/mcollective/runner.rb, line 48 48: def run 49: controltopic = Util.make_target("mcollective", :command) 50: @connection.subscribe(controltopic) 51: 52: # Start the registration plugin if interval isn't 0 53: begin 54: PluginManager["registration_plugin"].run(@connection) unless @config.registerinterval == 0 55: rescue Exception => e 56: @log.error("Failed to start registration plugin: #{e}") 57: end 58: 59: loop do 60: begin 61: msg = receive 62: dest = msg[:msgtarget] 63: 64: if dest =~ /#{controltopic}/ 65: @log.debug("Handling message for mcollectived controller") 66: 67: controlmsg(msg) 68: elsif dest =~ /#{@config.topicprefix}#{@config.topicsep}(.+)#{@config.topicsep}command/ 69: target = $1 70: 71: @log.debug("Handling message for #{target}") 72: 73: agentmsg(msg, target) 74: end 75: rescue Interrupt 76: @log.warn("Exiting after interrupt signal") 77: @connection.disconnect 78: exit! 79: 80: rescue NotTargettedAtUs => e 81: @log.debug("Message does not pass filters, ignoring") 82: 83: rescue Exception => e 84: @log.warn("Failed to handle message: #{e} - #{e.class}\n") 85: @log.warn(e.backtrace.join("\n\t")) 86: end 87: end 88: end