emyl / vagrant-triggers

Allow the definition of arbitrary scripts that will run on the host before and/or after Vagrant commands.
MIT License
546 stars 35 forks source link

run_remote fails #17

Closed brettlangdon closed 10 years ago

brettlangdon commented 10 years ago

Running into an issue where run_remote will not work because of a lock issue with vagrant and the vm. I read that this was resolved in/after 1.6.2, but it looks like it is still happening to me. Just wondering if you have seen this since or what the work around if for it?

Vagrant version:

$ vagrant --version
Vagrant 1.6.3

Vagrantfile:

# -*- mode: ruby -*-
# vi: set ft=ruby :
VAGRANTFILE_API_VERSION = "2"

Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
  config.vm.define :devbox do |devbox|
    [ ... ] # config here
    devbox.trigger.after [:up, :resume, :reload], :stdout => true do
      info "Restarting apache on vm"
      run_remote "sudo service apache2 restart"
    end
  end
end

Output:

$ vagrant reload
...
==> devbox: Running triggers after reload...
==> devbox: Restarting apache on vm
==> devbox: Executing command "vagrant ssh -c 'sudo service apache2 restart' devbox"...
The command "vagrant ssh -c 'sudo service apache2 restart' devbox" returned a failed exit code. The
error output is shown below:

An action 'read_state' was attempted on the machine 'devbox',
but another process is already executing an action on the machine.
Vagrant locks each machine for access by only one process at a time.
Please wait until the other Vagrant process finishes modifying this
machine, then try again.

If you believe this message is in error, please check the process
listing for any "ruby" or "vagrant" processes and kill them. Then
try again.
brettlangdon commented 10 years ago

nevermind, I think I found a work around for it:

devbox.trigger.after [:up, :resume, :reload] do
  info "Restarting apache on vm"
  @machine.communicate.sudo("service apache2 restart")
end
emyl commented 10 years ago

Thanks for reporting the issue. I must improve run_remote for avoiding issues like this and for working with multiple communicators. That's something I already had in mind.

Tagged as enhancement.

brettlangdon commented 10 years ago

:+1: