StepShutdown now always waits for the shutdown of the virtual machine to complete, not only if a shutdown command is specified

This commit is contained in:
Thomas Meckel 2019-07-26 11:33:39 +02:00
parent b873876670
commit d9b8623f64
1 changed files with 26 additions and 25 deletions

View File

@ -45,31 +45,6 @@ func (s *StepShutdown) Run(ctx context.Context, state multistep.StateBag) multis
return multistep.ActionHalt
}
// Wait for the machine to actually shut down
log.Printf("Waiting max %s for shutdown to complete", s.Timeout)
shutdownTimer := time.After(s.Timeout)
for {
running, _ := driver.IsRunning(vmName)
if !running {
if s.Delay.Nanoseconds() > 0 {
log.Printf("Delay for %s after shutdown to allow locks to clear...", s.Delay)
time.Sleep(s.Delay)
}
break
}
select {
case <-shutdownTimer:
err := errors.New("Timeout while waiting for machine to shut down.")
state.Put("error", err)
ui.Error(err.Error())
return multistep.ActionHalt
default:
time.Sleep(500 * time.Millisecond)
}
}
} else {
ui.Say("Halting the virtual machine...")
if err := driver.Stop(vmName); err != nil {
@ -80,6 +55,32 @@ func (s *StepShutdown) Run(ctx context.Context, state multistep.StateBag) multis
}
}
// Wait for the machine to actually shut down
log.Printf("Waiting max %s for shutdown to complete", s.Timeout)
shutdownTimer := time.After(s.Timeout)
for {
running, _ := driver.IsRunning(vmName)
if !running {
if s.Delay.Nanoseconds() > 0 {
log.Printf("Delay for %s after shutdown to allow locks to clear...", s.Delay)
time.Sleep(s.Delay)
}
break
}
select {
case <-shutdownTimer:
err := errors.New("Timeout while waiting for machine to shut down.")
state.Put("error", err)
ui.Error(err.Error())
return multistep.ActionHalt
default:
time.Sleep(500 * time.Millisecond)
}
}
log.Println("VM shut down.")
return multistep.ActionContinue
}