Skip to content

Commit

Permalink
fix: vm cleanup
Browse files Browse the repository at this point in the history
 Fallback to forcefully stop the virtual machine if it hasn't shut down gracefully.

Ref: #154

Signed-off-by: Ryan Johnson <ryan@tenthirtyam.org>
  • Loading branch information
tenthirtyam committed Sep 6, 2024
1 parent 6d0b1ec commit 5a92953
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion builder/vmware/common/step_shutdown.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ func (s *StepShutdown) Run(ctx context.Context, state multistep.StateBag) multis
return multistep.ActionHalt
}

// Wait for the machine to actually shut down
// Wait for the virtual machine to shut down.
log.Printf("Waiting up to %s for shutdown to complete", s.Timeout)
shutdownTimer := time.After(s.Timeout)
for {
Expand All @@ -67,6 +67,12 @@ func (s *StepShutdown) Run(ctx context.Context, state multistep.StateBag) multis
err := errors.New("timeout waiting for virtual machine to shut down")
state.Put("error", err)
ui.Error(err.Error())
// Fallback to forcefully stop the virtual machine if it hasn't shut down gracefully.
if err := driver.Stop(vmxPath); err != nil {
err := fmt.Errorf("error forcefully stopping virtual machine: %s", err)
state.Put("error", err)
ui.Error(err.Error())
}
return multistep.ActionHalt
default:
time.Sleep(150 * time.Millisecond)
Expand Down

0 comments on commit 5a92953

Please sign in to comment.