[aws|compute] better ssh handling for bootstrap

Closes #68
This commit is contained in:
geemus 2010-12-02 13:37:03 -08:00
parent c570a6bb10
commit 6ee69750f6
2 changed files with 12 additions and 4 deletions

View File

@ -152,7 +152,7 @@ module Fog
def setup(credentials = {})
requires :identity, :ip_address, :username
require 'json'
sleep(10) # takes a bit before EC2 instances will play nice
commands = [
%{mkdir .ssh},
%{passwd -l root},
@ -161,7 +161,16 @@ module Fog
if public_key
commands << %{echo "#{public_key}" >> ~/.ssh/authorized_keys}
end
Fog::SSH.new(ip_address, username, credentials).run(commands)
# allow some retries over the first 120 seconds because aws is weird
Timeout::timeout(120) do
begin
Timeout::timeout(4) do
Fog::SSH.new(ip_address, username, credentials).run(commands)
end
rescue Net::SSH::AuthenticationFailed, Timeout::Error
retry
end
end
rescue Errno::ECONNREFUSED => e
sleep(1)
retry

View File

@ -42,8 +42,7 @@ module Fog
require 'net/ssh'
@address = address
@username = username
@options = options.merge(:paranoid => false)
@options.merge(:verbose => true)
@options = { :paranoid => false }.merge(options)
end
def run(commands)