Retry on SSH#exec! as well

This commit is contained in:
Mitchell Hashimoto 2010-09-09 00:35:02 -07:00
parent f8e7431899
commit ea35608f64
2 changed files with 10 additions and 10 deletions

View File

@ -162,6 +162,8 @@ module Vagrant
# in order to provide basic command error checking while still
# providing access to the actual session object.
class Session
include Util::Retryable
attr_reader :session
def initialize(session)
@ -184,9 +186,7 @@ module Vagrant
ch[:result] << data if [:stdout, :stderr].include?(type)
end
tries = 5
begin
retryable(:tries => 5, :on => IOError, :sleep => 0.5) do
metach = session.open_channel do |channel|
channel.exec(command) do |ch, success|
raise "could not execute command: #{command.inspect}" unless success
@ -207,14 +207,11 @@ module Vagrant
end
end
end
rescue IOError
retry if (tries -= 1) > 0
raise
end
metach.wait
metach[:result]
end
end
# Checks for an erroroneous exit status and raises an exception
# if so.

View File

@ -13,7 +13,10 @@ module Vagrant
begin
return yield
rescue opts[:on]
retry if (opts[:tries] -= 1) > 0
if (opts[:tries] -= 1) > 0
sleep opts[:sleep].to_f if opts[:sleep]
retry
end
raise
end
end