From fddc058e43d21618f3c86994769b1524ac074fee Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Thu, 21 Jul 2011 10:53:01 -0700 Subject: [PATCH] Reconnect SSH if the session closes --- CHANGELOG.md | 2 +- lib/vagrant/ssh.rb | 10 ++++++++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index a8bdf6523..d301fedb4 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,6 @@ ## 0.8.2 (unreleased) - + - Fix issue with SSH disconnects not reconnecting. ## 0.8.1 (July 20, 2011) diff --git a/lib/vagrant/ssh.rb b/lib/vagrant/ssh.rb index bccb2c532..02232a5b2 100644 --- a/lib/vagrant/ssh.rb +++ b/lib/vagrant/ssh.rb @@ -76,6 +76,16 @@ module Vagrant # same options, and use that if possible session, options = @current_session + if session && options == opts + # Verify that the SSH session is still valid + begin + session.exec!("echo foo") + rescue IOError + # Reset the session, we need to reconnect + session = nil + end + end + if !session || options != opts env.logger.info("ssh") { "Connecting to SSH: #{env.config.ssh.host} #{opts[:port]}" }