Skip to content

Commit 7710562

Browse files
committed
hostagent: avoid requiring fuser and ss in the guest
No need to check the guestagent socket with `fuser` or `ss`, if the guestagent is actually functional Fix issue 2010 Signed-off-by: Akihiro Suda <[email protected]>
1 parent 95af163 commit 7710562

File tree

2 files changed

+33
-48
lines changed

2 files changed

+33
-48
lines changed

pkg/hostagent/hostagent.go

Lines changed: 33 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,8 @@ type HostAgent struct {
5757

5858
clientMu sync.RWMutex
5959
client guestagentclient.GuestAgentClient
60+
61+
guestAgentAliveCh chan struct{} // closed on establishing the connection
6062
}
6163

6264
type options struct {
@@ -160,19 +162,20 @@ func New(instName string, stdout io.Writer, sigintCh chan os.Signal, opts ...Opt
160162
})
161163

162164
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{}),
176179
}
177180
return a, nil
178181
}
@@ -492,6 +495,21 @@ sudo chown -R "${USER}" /run/host-services`
492495
if err := a.waitForRequirements("optional", a.optionalRequirements()); err != nil {
493496
errs = append(errs, err)
494497
}
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+
}
495513
if err := a.waitForRequirements("final", a.finalRequirements()); err != nil {
496514
errs = append(errs, err)
497515
}
@@ -605,6 +623,8 @@ func (a *HostAgent) processGuestAgentEvents(ctx context.Context, client guestage
605623
if err != nil {
606624
return err
607625
}
626+
logrus.Info("Guest agent is running")
627+
close(a.guestAgentAliveCh)
608628

609629
logrus.Debugf("guest agent info: %+v", info)
610630

pkg/hostagent/requirements.go

Lines changed: 0 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ import (
66
"time"
77

88
"github.com/lima-vm/lima/pkg/limayaml"
9-
"github.com/lima-vm/lima/pkg/store/filenames"
109
"github.com/lima-vm/sshocker/pkg/ssh"
1110
"github.com/sirupsen/logrus"
1211
)
@@ -120,40 +119,6 @@ fi
120119
debugHint: `Append "user_allow_other" to /etc/fuse.conf (/etc/fuse3.conf) in the guest`,
121120
})
122121
}
123-
if a.vSockPort != 0 {
124-
req = append(req, requirement{
125-
description: "the guest agent to be running",
126-
script: fmt.Sprintf(`#!/bin/bash
127-
set -eux -o pipefail
128-
if ! timeout 30s bash -c "until ss -a -n --vsock --listen | grep -q ':%d'; do sleep 3; done"; then
129-
echo >&2 "lima-guestagent is not installed yet"
130-
exit 1
131-
fi
132-
`, a.vSockPort),
133-
debugHint: fmt.Sprintf(`The guest agent with vsockPort %d does not seem running.
134-
Make sure that you are using an officially supported image.
135-
Also see "/var/log/cloud-init-output.log" in the guest.
136-
A possible workaround is to run "lima-guestagent install-systemd" in the guest.
137-
`, a.vSockPort),
138-
})
139-
} else {
140-
req = append(req, requirement{
141-
description: "the guest agent to be running",
142-
script: fmt.Sprintf(`#!/bin/bash
143-
set -eux -o pipefail
144-
sock="/dev/virtio-ports/%s"
145-
if ! timeout 30s bash -c "until sudo fuser \"${sock}\" || sudo lsof \"${sock}\"; do sleep 3; done"; then
146-
echo >&2 "lima-guestagent is not installed yet"
147-
exit 1
148-
fi
149-
`, filenames.VirtioPort),
150-
debugHint: fmt.Sprintf(`The guest agent with serialport /dev/virtio-ports/%s does not seem running.
151-
Make sure that you are using an officially supported image.
152-
Also see "/var/log/cloud-init-output.log" in the guest.
153-
A possible workaround is to run "lima-guestagent install-systemd" in the guest.
154-
`, filenames.VirtioPort),
155-
})
156-
}
157122
return req
158123
}
159124

0 commit comments

Comments
 (0)