Merge pull request #46 from fgrehm/8-fix-force-halt-when-nonresponsive

Fix GH-8
This commit is contained in:
Fabio Rehm 2013-10-18 14:52:11 -07:00
commit fa8c59a16c
3 changed files with 47 additions and 18 deletions

View file

@ -1,26 +1,26 @@
GIT
remote: git://github.com/fgrehm/vagrant-global-status.git
revision: 860a7ce70ff4596621af492e47eace5631f47324
revision: a0295400a0e47756cbcb8f97ed9f4449b1fb6b56
specs:
vagrant-global-status (0.1.0)
vagrant-global-status (0.1.1)
GIT
remote: git://github.com/fgrehm/vagrant-lxc.git
revision: 5ae82681cdedaf2a6f778e005dd65014fc7c2cec
revision: 225af5622767059708278db29d42941e93d41994
specs:
vagrant-lxc (0.5.1.dev)
vagrant-lxc (0.6.4.dev)
GIT
remote: git://github.com/fgrehm/vagrant-pristine.git
revision: 5c400d7850fc5f98d9601b59f4c3bd74818650de
revision: 4638491786943bfbf6f115b1fc379f069963fe46
specs:
vagrant-pristine (0.2.0)
vagrant-pristine (0.3.0)
GIT
remote: git://github.com/mitchellh/vagrant.git
revision: 16002d03c07f842a23497543129fa99f40f2bbc0
revision: 57e95323b6600b146167f0f14f83b22dd31dd03f
specs:
vagrant (1.2.8.dev)
vagrant (1.3.6.dev)
childprocess (~> 0.3.7)
erubis (~> 2.7.0)
i18n (~> 0.6.0)
@ -56,7 +56,7 @@ GEM
erubis (2.7.0)
ffi (1.9.0)
highline (1.6.19)
i18n (0.6.4)
i18n (0.6.5)
ipaddress (0.8.0)
json (1.7.7)
librarian (0.1.0)
@ -97,7 +97,7 @@ GEM
thor (0.18.1)
vagrant-librarian-chef (0.1.2)
librarian-chef
vagrant-omnibus (1.1.0)
vagrant-omnibus (1.1.2)
yajl-ruby (1.1.0)
PLATFORMS

View file

@ -1,3 +1,5 @@
require 'timeout'
module VagrantPlugins
module Cachier
class Action
@ -8,29 +10,54 @@ module VagrantPlugins
end
def call(env)
@env = env
@env = env
@machine = env[:machine]
if env[:machine].state.id == :running && symlinks.any?
if symlinks.any?
env[:ui].info I18n.t('vagrant_cachier.cleanup')
symlinks.each do |symlink|
remove_symlink symlink
if sshable?
symlinks.each do |symlink|
remove_symlink symlink
end
end
File.delete env[:machine].data_dir.join('cache_dirs').to_s
File.delete @machine.data_dir.join('cache_dirs').to_s
end
@app.call env
end
def sshable?
return if @machine.state.id != :running
# By default Vagrant will keep trying [1] to ssh connect to the VM for
# a long and we've got to prevent that from happening, so we just wait
# a few seconds and assume that the VM is halted / unresponsive and we
# carry on if it times out.
# [1] - https://github.com/mitchellh/vagrant/blob/57e95323b6600b146167f0f14f83b22dd31dd03f/plugins/communicators/ssh/communicator.rb#L185-L200
begin
Timeout.timeout(35) do
while true
return true if @machine.communicate.ready?
sleep 0.5
end
end
rescue Timeout::Error
@env[:ui].warn(I18n.t('vagrant_cachier.unable_to_ssh'))
end
return false
end
def symlinks
# TODO: Check if file exists instead of a blank rescue
@symlinks ||= @env[:machine].data_dir.join('cache_dirs').read.split rescue []
@symlinks ||= @machine.data_dir.join('cache_dirs').read.split rescue []
end
def remove_symlink(symlink)
if @env[:machine].communicate.test("test -L #{symlink}")
if @machine.communicate.test("test -L #{symlink}")
@logger.debug "Removing symlink for '#{symlink}'"
@env[:machine].communicate.sudo("unlink #{symlink}")
@machine.communicate.sudo("unlink #{symlink}")
end
end
end

View file

@ -11,6 +11,8 @@ en:
'%{current_path}' and it will be moved to
'%{new_path}' as it is the new path for keeping machine
scoped cache dirs starting with the 0.3.0 version of the plugin.
unable_to_ssh: |-
vagrant-cachier was unable to SSH into the VM to remove symlinks!
vagrant:
errors:
multiple_provider_specific_cache_dirs_found: |-