diff --git a/modules/create b/modules/create index fb1ed9c..5811b8a 100644 --- a/modules/create +++ b/modules/create @@ -258,7 +258,7 @@ create_site_maybe_restart_vagrant() { cd "$path" || error "Could not change directory." info "Running vagrant halt" hook "pre_creation_pre_vagrant_halt" - vagrant halt + vagrant_maybe_halt fi done } diff --git a/modules/delete b/modules/delete index f2aa5c3..32d4cc4 100644 --- a/modules/delete +++ b/modules/delete @@ -24,13 +24,7 @@ remove_site() { # @TODO refactor this if we need to cd "$path" || error "Could not change directory." hook "pre_site_removal_vagrant_halt" "$site" "$path" - - VMTEST="$(VBoxManage list runningvms)" - if [[ $VMTEST = *VVV* ]]; then - echo "Halting Vagrant" - vagrant halt - fi - + vagrant_maybe_halt hook "post_site_removal_vagrant_halt" "$site" "$path" # Delete the site folder diff --git a/modules/vagrant-commands b/modules/vagrant-commands index cb1a51c..bd4c414 100644 --- a/modules/vagrant-commands +++ b/modules/vagrant-commands @@ -11,3 +11,14 @@ run_vagrant_up() { hook "post_vagrant_provision" fi } + +vagrant_maybe_halt() { + # Test if VVV is running, using `VBoxManage` because it's much faster than `vagrant status` + VMTEST="$(VBoxManage list runningvms)" + if [[ $VMTEST = *VVV* ]]; then + info "Running \`vagrant halt\`" + vagrant halt + else + info "Vagrant not running, skipping \`vagrant halt\`..." + fi +}