MCPcopy
hub / github.com/lima-vm/lima / waitForInstanceShutdown

Function waitForInstanceShutdown

pkg/instance/stop.go:86–109  ·  view source on GitHub ↗
(ctx context.Context, inst *limatype.Instance)

Source from the content-addressed store, hash-verified

84}
85
86func waitForInstanceShutdown(ctx context.Context, inst *limatype.Instance) error {
87 ctx, cancel := context.WithTimeout(ctx, 3*time.Minute)
88 defer cancel()
89
90 ticker := time.NewTicker(500 * time.Millisecond)
91 defer ticker.Stop()
92
93 for {
94 select {
95 case <-ticker.C:
96 updatedInst, err := store.Inspect(ctx, inst.Name)
97 if err != nil {
98 return fmt.Errorf("failed to inspect instance status: %w", err)
99 }
100
101 if updatedInst.Status == limatype.StatusStopped {
102 logrus.Infof("The instance %s has shut down", updatedInst.Name)
103 return nil
104 }
105 case <-ctx.Done():
106 return errors.New("timed out waiting for instance to shut down after 3 minutes")
107 }
108 }
109}
110
111func StopForcibly(inst *limatype.Instance) {
112 if inst.DriverPID > 0 {

Callers 1

StopGracefullyFunction · 0.85

Calls 2

StopMethod · 0.95
InspectFunction · 0.92

Tested by

no test coverage detected