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

Function StartWithPaths

pkg/instance/start.go:168–284  ·  view source on GitHub ↗

StartWithPaths starts the hostagent in the background, which in turn will start the instance. StartWithPaths will listen to hostagent events and log them to STDOUT until either the instance is running, or has failed to start. The launchHostAgentForeground argument makes the hostagent run in the for

(ctx context.Context, inst *limatype.Instance, launchHostAgentForeground, showProgress bool, limactl, guestAgent string)

Source from the content-addressed store, hash-verified

166//
167// StartWithPaths calls Prepare by itself, so you do not need to call Prepare manually before calling Start.
168func StartWithPaths(ctx context.Context, inst *limatype.Instance, launchHostAgentForeground, showProgress bool, limactl, guestAgent string) error {
169 haPIDPath := filepath.Join(inst.Dir, filenames.HostAgentPID)
170 if _, err := os.Stat(haPIDPath); !errors.Is(err, os.ErrNotExist) {
171 return fmt.Errorf("instance %q seems running (hint: remove %q if the instance is not actually running)", inst.Name, haPIDPath)
172 }
173 logrus.Infof("Starting the instance %q with %s VM driver %q", inst.Name, registry.CheckInternalOrExternal(inst.VMType), inst.VMType)
174
175 haSockPath := filepath.Join(inst.Dir, filenames.HostAgentSock)
176
177 prepared, err := Prepare(ctx, inst, guestAgent)
178 if err != nil {
179 return err
180 }
181
182 if limactl == "" {
183 limactl, err = os.Executable()
184 if err != nil {
185 return err
186 }
187 }
188 haStdoutPath := filepath.Join(inst.Dir, filenames.HostAgentStdoutLog)
189 haStderrPath := filepath.Join(inst.Dir, filenames.HostAgentStderrLog)
190
191 begin := time.Now() // used for logrus propagation
192 var haCmd *exec.Cmd
193 if isRegisteredToAutoStart, err := autostart.IsRegistered(ctx, inst); err != nil && !errors.Is(err, autostart.ErrNotSupported) {
194 return fmt.Errorf("failed to check autostart registration: %w", err)
195 } else if !isRegisteredToAutoStart || launchHostAgentForeground {
196 if err := os.RemoveAll(haStdoutPath); err != nil {
197 return err
198 }
199 if err := os.RemoveAll(haStderrPath); err != nil {
200 return err
201 }
202 haStdoutW, err := os.Create(haStdoutPath)
203 if err != nil {
204 return err
205 }
206 // no defer haStdoutW.Close()
207 haStderrW, err := os.Create(haStderrPath)
208 if err != nil {
209 return err
210 }
211 // no defer haStderrW.Close()
212
213 var args []string
214 if logrus.GetLevel() >= logrus.DebugLevel {
215 args = append(args, "--debug")
216 }
217 args = append(args,
218 "hostagent",
219 "--pidfile", haPIDPath,
220 "--socket", haSockPath)
221 if prepared.Driver.Info(ctx).Features.CanRunGUI {
222 args = append(args, "--run-gui")
223 }
224 if prepared.GuestAgent != "" {
225 args = append(args, "--guestagent", prepared.GuestAgent)

Callers 1

StartFunction · 0.85

Calls 10

CheckInternalOrExternalFunction · 0.92
IsRegisteredFunction · 0.92
RequestStartFunction · 0.92
PrepareFunction · 0.85
waitHostAgentStartFunction · 0.85
watchHostAgentEventsFunction · 0.85
execHostAgentForegroundFunction · 0.70
CreateMethod · 0.65
InfoMethod · 0.65
StartMethod · 0.65

Tested by

no test coverage detected