How to doing polling in a recipe


#1

Currently remote_file resource keeps getting the following error:

Error connecting to
http://omakase.mspot.com/yum/5/x86_64/omakase-release-5-2.noarch.rpm -
Connection timed out - connect(2)

Basically the network configuration is not ready when the recipe got triggered.
I would hope there is a resource I can use to wait and poll the status.

Is there a way to fix this?


#2

On Mon, Oct 15, 2012 at 2:17 PM, xyuan@mspot.com wrote:

Basically the network configuration is not ready when the recipe got triggered.
I would hope there is a resource I can use to wait and poll the status.

Is there a way to fix this?

Put this in a cookbook and put it at the top of your run list or base role.

ruby_block “check_internet” do
block do
require ‘socket’

test_host = "www.google.com"
test_port = "www"
retries = 0

begin
  s = TCPSocket.new(test_host, test_port)
  s.close

rescue Errno::ETIMEDOUT
  if retries < 3
    retries += 1
    Chef::Log.logger.send("warn", "Unable to connect to

#{test_host}:#{test_port}, retry ##{retries}")
retry
end
end
end
end