port_open?

in chef/cookbooks/uber_helpers/libraries/node_utils.rb [743:768]


    def port_open?(destination, port, timeout = 1)
      begin
        socket = Socket.tcp(destination, port, :connect_timeout => timeout)
      rescue Errno::ETIMEDOUT
        Chef::Log.warn("node.port_open? #{destination} timed out")
        return false
      rescue SocketError
        Chef::Log.warn("node.port_open? cannot resolve #{destination}")
        return false
      rescue Errno::ECONNREFUSED
        Chef::Log.warn("node.port_open? #{destination} connection refused")
        return false
      rescue Errno::EHOSTUNREACH
        Chef::Log.warn("node.port_open? #{destination} host unreachable")
        return false
      end
      if socket
        unless socket.closed?
          socket.close
        end
        true
      else
        false
      end
    end