Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

respace

  • Loading branch information...
commit edb5a86b49e601cf32573ddcc4e8be37541c9c75 1 parent 1a13290
@ripienaar authored
Showing with 59 additions and 59 deletions.
  1. +59 −59 registration/mcollective-registration-receiver.rb
View
118 registration/mcollective-registration-receiver.rb
@@ -3,84 +3,84 @@
require 'mcollective'
module MCollective
- class Util::RegistrationDaemon
- def initialize
- oparser = Optionparser.new
- options = oparser.parse
+ class Util::RegistrationDaemon
+ def initialize
+ oparser = Optionparser.new
+ options = oparser.parse
- @config = Config.instance
- @config.loadconfig(options[:config])
+ @config = Config.instance
+ @config.loadconfig(options[:config])
- @connector = PluginManager["connector_plugin"]
- @connector.connect
+ @connector = PluginManager["connector_plugin"]
+ @connector.connect
- queue = Config.instance.pluginconf["registration_daemon_queue"] || "/queue/mcollective.registration"
- Log.info("Subscribing to #{queue} for new events")
+ queue = Config.instance.pluginconf["registration_daemon_queue"] || "/queue/mcollective.registration"
+ Log.info("Subscribing to #{queue} for new events")
- @connector.connection.subscribe(queue)
+ @connector.connection.subscribe(queue)
- Util.loadclass("MCollective::Agent::Registration")
+ Util.loadclass("MCollective::Agent::Registration")
- @agent = Agent::Registration.new
+ @agent = Agent::Registration.new
- Log.info("MCollective Registration daemon started")
- end
+ Log.info("MCollective Registration daemon started")
+ end
- def daemonize
- fork do
- Process.setsid
- exit if fork
- Dir.chdir('/tmp')
- STDIN.reopen('/dev/null')
- STDOUT.reopen('/dev/null', 'a')
- STDERR.reopen('/dev/null', 'a')
-
- yield
- end
- end
+ def daemonize
+ fork do
+ Process.setsid
+ exit if fork
+ Dir.chdir('/tmp')
+ STDIN.reopen('/dev/null')
+ STDOUT.reopen('/dev/null', 'a')
+ STDERR.reopen('/dev/null', 'a')
+
+ yield
+ end
+ end
- def run
- if Config.instance.daemonize
- daeminize { receive_loop }
- else
- receive_loop
- end
- end
+ def run
+ if Config.instance.daemonize
+ daeminize { receive_loop }
+ else
+ receive_loop
+ end
+ end
- def receive_loop
- loop do
- begin
- msg = @connector.connection.receive
+ def receive_loop
+ loop do
+ begin
+ msg = @connector.connection.receive
- start_time = Time.now
+ start_time = Time.now
- registration_data = JSON.load(msg.body)
+ registration_data = JSON.load(msg.body)
- raise RPCAborted, "Did not receive a FQDN fact" unless registration_data["facts"].include?("fqdn")
+ raise RPCAborted, "Did not receive a FQDN fact" unless registration_data["facts"].include?("fqdn")
- sender = registration_data["facts"]["fqdn"]
- registration_msg = {:senderid => sender, :body => registration_data}
+ sender = registration_data["facts"]["fqdn"]
+ registration_msg = {:senderid => sender, :body => registration_data}
- begin
- @agent.handlemsg(registration_msg, @connector)
- rescue Exception => e
- raise RPCAborted, "registration raised an unexpected exception: #{e.class}: #{e}"
- end
+ begin
+ @agent.handlemsg(registration_msg, @connector)
+ rescue Exception => e
+ raise RPCAborted, "registration raised an unexpected exception: #{e.class}: #{e}"
+ end
- Log.info("Processed registration data from %s in %.2f seconds" % [sender, (Time.now - start_time).to_f])
+ Log.info("Processed registration data from %s in %.2f seconds" % [sender, (Time.now - start_time).to_f])
- rescue RPCAborted
- Log.warn("Failed to handle registration data: #{e}")
- rescue Interrupt
- Log.info("Exiting on interrupt signal")
- exit
- rescue Exception => e
- Log.error("Unexpected Exception: #{e.class}: #{e}")
- sleep 1
- end
- end
+ rescue RPCAborted
+ Log.warn("Failed to handle registration data: #{e}")
+ rescue Interrupt
+ Log.info("Exiting on interrupt signal")
+ exit
+ rescue Exception => e
+ Log.error("Unexpected Exception: #{e.class}: #{e}")
+ sleep 1
end
+ end
end
+ end
end
receiver = MCollective::Util::RegistrationDaemon.new
Please sign in to comment.
Something went wrong with that request. Please try again.