@@ -109,9 +109,20 @@ func Prepare(ctx context.Context, inst *store.Instance) (*Prepared, error) {
109
109
}, nil
110
110
}
111
111
112
- // Start starts the instance.
112
+ // Start starts the hostagent in the background, which in turn will start the instance.
113
+ // Start will listen to hostagent events and log them to STDOUT until either the instance
114
+ // is running, or has failed to start.
115
+ //
116
+ // The `limactl` argument allows the caller to specify the full path of the `limactl` executable.
117
+ // When called from inside limactl itself it will always be the empty string which uses the name
118
+ // of the current executable instead.
119
+ //
120
+ // The `launchHostAgentForeground` argument makes the hostagent run in the foreground.
121
+ // The function will continue to listen and log hostagent events until the instance is
122
+ // shut down again.
123
+ //
113
124
// Start calls Prepare by itself, so you do not need to call Prepare manually before calling Start.
114
- func Start (ctx context.Context , inst * store.Instance , launchHostAgentForeground bool ) error {
125
+ func Start (ctx context.Context , inst * store.Instance , limactl string , launchHostAgentForeground bool ) error {
115
126
haPIDPath := filepath .Join (inst .Dir , filenames .HostAgentPID )
116
127
if _ , err := os .Stat (haPIDPath ); ! errors .Is (err , os .ErrNotExist ) {
117
128
return fmt .Errorf ("instance %q seems running (hint: remove %q if the instance is not actually running)" , inst .Name , haPIDPath )
@@ -144,9 +155,11 @@ func Start(ctx context.Context, inst *store.Instance, launchHostAgentForeground
144
155
return err
145
156
}
146
157
147
- self , err := os .Executable ()
148
- if err != nil {
149
- return err
158
+ if limactl == "" {
159
+ limactl , err = os .Executable ()
160
+ if err != nil {
161
+ return err
162
+ }
150
163
}
151
164
haStdoutPath := filepath .Join (inst .Dir , filenames .HostAgentStdoutLog )
152
165
haStderrPath := filepath .Join (inst .Dir , filenames .HostAgentStderrLog )
@@ -182,7 +195,7 @@ func Start(ctx context.Context, inst *store.Instance, launchHostAgentForeground
182
195
args = append (args , "--nerdctl-archive" , prepared .NerdctlArchiveCache )
183
196
}
184
197
args = append (args , inst .Name )
185
- haCmd := exec .CommandContext (ctx , self , args ... )
198
+ haCmd := exec .CommandContext (ctx , limactl , args ... )
186
199
187
200
if launchHostAgentForeground {
188
201
haCmd .SysProcAttr = executil .ForegroundSysProcAttr
@@ -214,7 +227,7 @@ func Start(ctx context.Context, inst *store.Instance, launchHostAgentForeground
214
227
return err
215
228
}
216
229
}
217
- if err := syscall .Exec (self , haCmd .Args , haCmd .Environ ()); err != nil {
230
+ if err := syscall .Exec (limactl , haCmd .Args , haCmd .Environ ()); err != nil {
218
231
return err
219
232
}
220
233
} else if err := haCmd .Start (); err != nil {
0 commit comments