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:
parent
b873876670
commit
d9b8623f64
|
@ -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
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue