@@ -44,9 +44,8 @@ type Prepared struct {
4444}
4545
4646// Prepare ensures the disk, the nerdctl archive, etc.
47- func Prepare (ctx context.Context , inst * limatype.Instance ) (* Prepared , error ) {
48- var guestAgent string
49- if ! * inst .Config .Plain {
47+ func Prepare (ctx context.Context , inst * limatype.Instance , guestAgent string ) (* Prepared , error ) {
48+ if ! * inst .Config .Plain && guestAgent == "" {
5049 var err error
5150 guestAgent , err = usrlocalsharelima .GuestAgentBinary (* inst .Config .OS , * inst .Config .Arch )
5251 if err != nil {
@@ -131,20 +130,24 @@ func Prepare(ctx context.Context, inst *limatype.Instance) (*Prepared, error) {
131130 }, nil
132131}
133132
134- // Start starts the hostagent in the background, which in turn will start the instance.
135- // Start will listen to hostagent events and log them to STDOUT until either the instance
133+ // StartWithPaths starts the hostagent in the background, which in turn will start the instance.
134+ // StartWithPaths will listen to hostagent events and log them to STDOUT until either the instance
136135// is running, or has failed to start.
137136//
138- // The `limactl` argument allows the caller to specify the full path of the `limactl` executable.
139- // When called from inside limactl itself it will always be the empty string which uses the name
140- // of the current executable instead.
141- //
142- // The `launchHostAgentForeground` argument makes the hostagent run in the foreground.
137+ // The launchHostAgentForeground argument makes the hostagent run in the foreground.
143138// The function will continue to listen and log hostagent events until the instance is
144139// shut down again.
145140//
146- // Start calls Prepare by itself, so you do not need to call Prepare manually before calling Start.
147- func Start (ctx context.Context , inst * limatype.Instance , limactl string , launchHostAgentForeground , showProgress bool ) error {
141+ // The showProgress argument tells the hostagent to show provision script progress by tailing cloud-init logs.
142+ //
143+ // The limactl argument allows the caller to specify the full path of the limactl executable.
144+ // The guestAgent argument allows the caller to specify the full path of the guest agent executable.
145+ // Inside limactl this function is only called by Start, which passes empty strings for both
146+ // limactl and guestAgent, in which case the location of the current executable is used for
147+ // limactl and the guest agent is located from the corresponding <prefix>/share/lima directory.
148+ //
149+ // StartWithPaths calls Prepare by itself, so you do not need to call Prepare manually before calling Start.
150+ func StartWithPaths (ctx context.Context , inst * limatype.Instance , launchHostAgentForeground , showProgress bool , limactl , guestAgent string ) error {
148151 haPIDPath := filepath .Join (inst .Dir , filenames .HostAgentPID )
149152 if _ , err := os .Stat (haPIDPath ); ! errors .Is (err , os .ErrNotExist ) {
150153 return fmt .Errorf ("instance %q seems running (hint: remove %q if the instance is not actually running)" , inst .Name , haPIDPath )
@@ -153,7 +156,7 @@ func Start(ctx context.Context, inst *limatype.Instance, limactl string, launchH
153156
154157 haSockPath := filepath .Join (inst .Dir , filenames .HostAgentSock )
155158
156- prepared , err := Prepare (ctx , inst )
159+ prepared , err := Prepare (ctx , inst , guestAgent )
157160 if err != nil {
158161 return err
159162 }
@@ -251,6 +254,10 @@ func Start(ctx context.Context, inst *limatype.Instance, limactl string, launchH
251254 }
252255}
253256
257+ func Start (ctx context.Context , inst * limatype.Instance , launchHostAgentForeground , showProgress bool ) error {
258+ return StartWithPaths (ctx , inst , launchHostAgentForeground , showProgress , "" , "" )
259+ }
260+
254261func waitHostAgentStart (_ context.Context , haPIDPath , haStderrPath string ) error {
255262 begin := time .Now ()
256263 deadlineDuration := 5 * time .Second
0 commit comments