From 759bbd046be0d2e3c4c52c7c0108cbb7025d47c2 Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Tue, 14 Sep 2010 15:00:46 -0600 Subject: [PATCH] Raise proper exception if SSH connection is refused with message to help people. --- lib/vagrant/errors.rb | 5 +++++ lib/vagrant/ssh.rb | 4 +++- templates/locales/en.yml | 7 +++++++ 3 files changed, 15 insertions(+), 1 deletion(-) diff --git a/lib/vagrant/errors.rb b/lib/vagrant/errors.rb index 23846a999..fefac2c08 100644 --- a/lib/vagrant/errors.rb +++ b/lib/vagrant/errors.rb @@ -199,6 +199,11 @@ module Vagrant error_key(:ssh_authentication_failed) end + class SSHConnectionRefused < VagrantError + status_code(43) + error_key(:ssh_connection_refused) + end + class SSHKeyBadPermissions < VagrantError status_code(12) error_key(:ssh_key_bad_permissions) diff --git a/lib/vagrant/ssh.rb b/lib/vagrant/ssh.rb index 8bfc8b3cd..6c0c969b2 100644 --- a/lib/vagrant/ssh.rb +++ b/lib/vagrant/ssh.rb @@ -70,6 +70,8 @@ module Vagrant yield SSH::Session.new(ssh) end end + rescue Errno::ECONNREFUSED + raise Errors::SSHConnectionRefused.new end # Uploads a file from `from` to `to`. `from` is expected to be a filename @@ -94,7 +96,7 @@ module Vagrant execute(:timeout => env.config.ssh.timeout) do |ssh| Thread.current[:result] = true end - rescue Errno::ECONNREFUSED, Net::SSH::Disconnect + rescue Errno::ECONNREFUSED, Net::SSH::Disconnect, Errors::SSHConnectionRefused # False, its defaulted above end end diff --git a/templates/locales/en.yml b/templates/locales/en.yml index 6b0da9012..d72f4daef 100644 --- a/templates/locales/en.yml +++ b/templates/locales/en.yml @@ -27,6 +27,13 @@ en: Vagrant assumes that this means the command failed! %{command} + ssh_connection_refused: |- + SSH connection was refused! This usually happens if the VM failed to + boot properly. Some steps to try to fix this: First, try reloading your + VM with `vagrant reload`, since a simple restart sometimes fixes things. + If that doesn't work, destroy your VM and recreate it with a `vagrant destroy` + followed by a `vagrant up`. If that doesn't work, contact a Vagrant + maintainer (support channels listed on the website) for more assistance. ssh_key_bad_permissions: |- The private key to connect to this box via SSH has invalid permissions set on it. The permissions of the private key should be set to 0600, otherwise SSH will