builder/virtualbox: only power off the machine if it isrunning

This commit is contained in:
Mitchell Hashimoto
2013-06-23 22:00:40 -07:00
parent f6113de170
commit d4cdccb51b
+5 -2
View File
@@ -48,7 +48,10 @@ func (s *stepRun) Cleanup(state map[string]interface{}) {
driver := state["driver"].(Driver)
ui := state["ui"].(packer.Ui)
if err := driver.VBoxManage("controlvm", s.vmName, "poweroff"); err != nil {
ui.Error(fmt.Sprintf("Error shutting down VM: %s", err))
if running, _ := driver.IsRunning(s.vmName); running {
if err := driver.VBoxManage("controlvm", s.vmName, "poweroff"); err != nil {
ui.Error(fmt.Sprintf("Error shutting down VM: %s", err))
}
}
}