Slide 21
Slide 21 text
Ruby, when you need it
ruby_block "configure-replica-set" do
block do
require "rubygems"
require "mongo"
if node['mongodb']['replicaset'].nil?
Chef::Log.warn("recipe[mongodb::replset] applied to node without mongodb.replicaset attribute, skipping")
next
end
# Retry 5 times, as we believe that there should
# be a mongod accepting connections on localhost
conn = nil
10.times do |try|
begin
conn = Mongo::Connection.new(
"localhost", node['mongodb']['port'],
:slave_ok => true, :connect_timeout => 5)
rescue
delay = 2 ** (try + 1)
Chef::Log.info("Failed to connect to mongodb, sleeping #{delay}, try #{try}/10")
sleep(delay)
end
end
end