mirror of
https://github.com/containers/podman.git
synced 2025-07-03 01:08:02 +08:00
Merge pull request #23097 from Luap99/machine-stop
pkg/machine/apple: machine stop timeout
This commit is contained in:
@ -6,7 +6,6 @@ import (
|
|||||||
"bytes"
|
"bytes"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
|
||||||
"io"
|
"io"
|
||||||
"net/http"
|
"net/http"
|
||||||
"time"
|
"time"
|
||||||
@ -89,33 +88,28 @@ func (vf *Helper) stateChange(newState rest.StateChange) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (vf *Helper) Stop(force, wait bool) error {
|
func (vf *Helper) Stop(force, wait bool) error {
|
||||||
waitDuration := time.Millisecond * 10
|
state := rest.Stop
|
||||||
// TODO Add ability to wait until stopped
|
|
||||||
if force {
|
if force {
|
||||||
if err := vf.stateChange(rest.HardStop); err != nil {
|
state = rest.HardStop
|
||||||
return err
|
}
|
||||||
}
|
if err := vf.stateChange(state); err != nil {
|
||||||
} else {
|
return err
|
||||||
if err := vf.stateChange(rest.Stop); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
if !wait {
|
if !wait {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
waitErr := fmt.Errorf("failed waiting for vm to stop")
|
waitDuration := time.Millisecond * 500
|
||||||
// Backoff to wait on the machine shutdown
|
// Wait up to 90s then hard force off
|
||||||
for i := 0; i < 11; i++ {
|
for i := 0; i < 180; i++ {
|
||||||
_, err := vf.getRawState()
|
_, err := vf.getRawState()
|
||||||
if err != nil || errors.Is(err, unix.ECONNREFUSED) {
|
if err != nil || errors.Is(err, unix.ECONNREFUSED) {
|
||||||
waitErr = nil
|
return nil
|
||||||
break
|
|
||||||
}
|
}
|
||||||
waitDuration *= 2
|
|
||||||
logrus.Debugf("backoff wait time: %s", waitDuration.String())
|
|
||||||
time.Sleep(waitDuration)
|
time.Sleep(waitDuration)
|
||||||
}
|
}
|
||||||
return waitErr
|
logrus.Warn("Failed to gracefully stop machine, performing hard stop")
|
||||||
|
// we waited long enough do a hard stop
|
||||||
|
return vf.stateChange(rest.HardStop)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Helper describes the use of vfkit: cmdline and endpoint
|
// Helper describes the use of vfkit: cmdline and endpoint
|
||||||
|
Reference in New Issue
Block a user