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