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

Using :force => true does not handle remote_run failing to connect to the node #55

Closed supernomad closed 8 years ago

supernomad commented 8 years ago

When using the following trigger:

config.trigger.before :destroy, :vm => vm_name, :force => true, :stdout => false, :stderr => false do
        run_remote "/usr/bin/docker exec postgres /bin/bash -c \"su postgres -c '/usr/pgsql-9.4/bin/pg_ctl stop -m fast -D /var/lib/postgres'\""
end

If the VM happens to not be running during a destroy the destroy process fails because the run_remote cannot connect to the node. Is there something I am missing here? Is there anyway to only run the command if the node is actively running?

Exception:

==> core02: Running triggers before destroy...
==> core02: Executing remote command "/usr/bin/docker exec postgres /bin/bash -c "su postgres -c '/usr/pgsql-9.4/bin/pg_ctl stop -m fast -D /var/lib/postgres'""...
The provider for this Vagrant-managed machine is reporting that it
is not yet ready for SSH. Depending on your provider this can carry
different meanings. Make sure your machine is created and running and
try again. Additionally, check the output of `vagrant status` to verify
that the machine is in the state that you expect. If you continue to
get this error message, please view the documentation for the provider
you're using.