Retry on SSH#exec! as well
This commit is contained in:
parent
f8e7431899
commit
ea35608f64
|
@ -162,6 +162,8 @@ module Vagrant
|
||||||
# in order to provide basic command error checking while still
|
# in order to provide basic command error checking while still
|
||||||
# providing access to the actual session object.
|
# providing access to the actual session object.
|
||||||
class Session
|
class Session
|
||||||
|
include Util::Retryable
|
||||||
|
|
||||||
attr_reader :session
|
attr_reader :session
|
||||||
|
|
||||||
def initialize(session)
|
def initialize(session)
|
||||||
|
@ -184,9 +186,7 @@ module Vagrant
|
||||||
ch[:result] << data if [:stdout, :stderr].include?(type)
|
ch[:result] << data if [:stdout, :stderr].include?(type)
|
||||||
end
|
end
|
||||||
|
|
||||||
tries = 5
|
retryable(:tries => 5, :on => IOError, :sleep => 0.5) do
|
||||||
|
|
||||||
begin
|
|
||||||
metach = session.open_channel do |channel|
|
metach = session.open_channel do |channel|
|
||||||
channel.exec(command) do |ch, success|
|
channel.exec(command) do |ch, success|
|
||||||
raise "could not execute command: #{command.inspect}" unless success
|
raise "could not execute command: #{command.inspect}" unless success
|
||||||
|
@ -207,13 +207,10 @@ module Vagrant
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
rescue IOError
|
|
||||||
retry if (tries -= 1) > 0
|
|
||||||
raise
|
|
||||||
end
|
|
||||||
|
|
||||||
metach.wait
|
metach.wait
|
||||||
metach[:result]
|
metach[:result]
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
# Checks for an erroroneous exit status and raises an exception
|
# Checks for an erroroneous exit status and raises an exception
|
||||||
|
|
|
@ -13,7 +13,10 @@ module Vagrant
|
||||||
begin
|
begin
|
||||||
return yield
|
return yield
|
||||||
rescue opts[:on]
|
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
|
raise
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in New Issue