Permalink
Browse files

NATS connectivity error checks. Start NATS registration only

if mbus configuration is available.

Change-Id: I55c74883249d4b4050da0ceecbb140b5f7b3f543
  • Loading branch information...
1 parent 0e35f0f commit a93fffd28d22e51cdd84bc5abf6a5ee96c711800 @joeldsa joeldsa committed Mar 20, 2012
Showing with 37 additions and 13 deletions.
  1. +36 −12 bin/acm
  2. +1 −1 config/acm.yml
View
48 bin/acm
@@ -41,23 +41,47 @@ ACM::Config.configure(config)
event_thread = Thread.new { EM.run }
+EM.error_handler do |e|
+ ACM::Config.logger.error "Eventmachine problem, #{e}"
+ ACM::Config.logger.error(e)
+ # Fail fast
+ STDERR.puts "Eventmachine problem, #{e}"
+ exit 1
+end
+
require "acm_controller"
require "vcap/component"
require "vcap/common"
require "utils"
-EM.next_tick do
- NATS.start(:uri => config["mbus"]) do
- VCAP::Component.register(:type => "ACM",
- :index => config[:index] || 0,
- :config => config,
- :logger => ACM::Config.logger)
-
- ACM::Config.logger.debug "varz #{VCAP::Component.varz[:host]} #{VCAP::Component.varz[:credentials]}}"
- VCAP::Component.varz[:requests] = 0
- VCAP::Component.varz[:requests_per_sec] = 0
- VCAP::Component.varz[:revision] = ACM::Config.revision
- ACM::Varz.setup_updates
+if config["mbus"]
+ NATS.on_error do |e|
+ if e.kind_of? NATS::ConnectError
+ ACM::Config.logger.error("EXITING! NATS connection failed: #{e}")
+ ACM::Config.logger.error(e)
+
+ # Fail fast
+ STDERR.puts("EXITING! NATS connection failed: #{e}")
+ exit!
+ else
+ ACM::Config.logger.error("NATS problem, #{e}")
+ ACM::Config.logger.error(e)
+ end
+ end
+
+ EM.next_tick do
+ NATS.start(:uri => config["mbus"]) do
+ VCAP::Component.register(:type => "ACM",
+ :index => config[:index] || 0,
+ :config => config,
+ :logger => ACM::Config.logger)
+
+ ACM::Config.logger.debug "varz #{VCAP::Component.varz[:host]} #{VCAP::Component.varz[:credentials]}}"
+ VCAP::Component.varz[:requests] = 0
+ VCAP::Component.varz[:requests_per_sec] = 0
+ VCAP::Component.varz[:revision] = ACM::Config.revision
+ ACM::Varz.setup_updates
+ end
end
end
View
@@ -2,7 +2,7 @@
pid: /var/vcap/sys/run/acm/acm.pid
name: ACM
port: 9090
-mbus: nats://localhost:4222/
+#mbus: nats://localhost:4222/
logging:
level: debug
file: /tmp/acm.log

0 comments on commit a93fffd

Please sign in to comment.