@@ -57,6 +57,8 @@ type HostAgent struct {
57
57
58
58
clientMu sync.RWMutex
59
59
client guestagentclient.GuestAgentClient
60
+
61
+ guestAgentAliveCh chan struct {} // closed on establishing the connection
60
62
}
61
63
62
64
type options struct {
@@ -160,19 +162,20 @@ func New(instName string, stdout io.Writer, sigintCh chan os.Signal, opts ...Opt
160
162
})
161
163
162
164
a := & HostAgent {
163
- y : y ,
164
- sshLocalPort : sshLocalPort ,
165
- udpDNSLocalPort : udpDNSLocalPort ,
166
- tcpDNSLocalPort : tcpDNSLocalPort ,
167
- instDir : inst .Dir ,
168
- instName : instName ,
169
- instSSHAddress : inst .SSHAddress ,
170
- sshConfig : sshConfig ,
171
- portForwarder : newPortForwarder (sshConfig , sshLocalPort , rules , inst .VMType ),
172
- driver : limaDriver ,
173
- sigintCh : sigintCh ,
174
- eventEnc : json .NewEncoder (stdout ),
175
- vSockPort : vSockPort ,
165
+ y : y ,
166
+ sshLocalPort : sshLocalPort ,
167
+ udpDNSLocalPort : udpDNSLocalPort ,
168
+ tcpDNSLocalPort : tcpDNSLocalPort ,
169
+ instDir : inst .Dir ,
170
+ instName : instName ,
171
+ instSSHAddress : inst .SSHAddress ,
172
+ sshConfig : sshConfig ,
173
+ portForwarder : newPortForwarder (sshConfig , sshLocalPort , rules , inst .VMType ),
174
+ driver : limaDriver ,
175
+ sigintCh : sigintCh ,
176
+ eventEnc : json .NewEncoder (stdout ),
177
+ vSockPort : vSockPort ,
178
+ guestAgentAliveCh : make (chan struct {}),
176
179
}
177
180
return a , nil
178
181
}
@@ -492,6 +495,21 @@ sudo chown -R "${USER}" /run/host-services`
492
495
if err := a .waitForRequirements ("optional" , a .optionalRequirements ()); err != nil {
493
496
errs = append (errs , err )
494
497
}
498
+ if ! * a .y .Plain {
499
+ logrus .Info ("Waiting for the guest agent to be running" )
500
+ select {
501
+ case <- a .guestAgentAliveCh :
502
+ // NOP
503
+ case <- time .After (time .Minute ):
504
+ err := errors .New ("guest agent does not seem to be running; port forwards will not work" )
505
+ if * a .y .VMType == limayaml .WSL2 {
506
+ // geustagent is currently not available for WSL2: https://github.com/lima-vm/lima/issues/2025
507
+ logrus .Warn (err )
508
+ } else {
509
+ errs = append (errs , err )
510
+ }
511
+ }
512
+ }
495
513
if err := a .waitForRequirements ("final" , a .finalRequirements ()); err != nil {
496
514
errs = append (errs , err )
497
515
}
@@ -605,6 +623,8 @@ func (a *HostAgent) processGuestAgentEvents(ctx context.Context, client guestage
605
623
if err != nil {
606
624
return err
607
625
}
626
+ logrus .Info ("Guest agent is running" )
627
+ close (a .guestAgentAliveCh )
608
628
609
629
logrus .Debugf ("guest agent info: %+v" , info )
610
630
0 commit comments