Skip to content

Commit 45213e3

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 45213e3

File tree

2 files changed

+22
-35
lines changed

2 files changed

+22
-35
lines changed

pkg/hostagent/hostagent.go

+22
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,9 @@ type HostAgent struct {
5757

5858
clientMu sync.RWMutex
5959
client guestagentclient.GuestAgentClient
60+
61+
guestAgentAlive *time.Time
62+
guestAgentAliveMu sync.RWMutex
6063
}
6164

6265
type options struct {
@@ -495,6 +498,20 @@ sudo chown -R "${USER}" /run/host-services`
495498
if err := a.waitForRequirements("final", a.finalRequirements()); err != nil {
496499
errs = append(errs, err)
497500
}
501+
if !*a.y.Plain {
502+
a.guestAgentAliveMu.RLock()
503+
guestAgentAlive := a.guestAgentAlive
504+
a.guestAgentAliveMu.RUnlock()
505+
if guestAgentAlive == nil {
506+
err := errors.New("lima-guestagent does not seem to be running; port forwards will not work")
507+
if *a.y.VMType == limayaml.WSL2 {
508+
// geustagent is currently not available for WSL2: https://github.com/lima-vm/lima/issues/2025
509+
logrus.Warn(err)
510+
} else {
511+
errs = append(errs, err)
512+
}
513+
}
514+
}
498515
// Copy all config files _after_ the requirements are done
499516
for _, rule := range a.y.CopyToHost {
500517
if err := copyToHost(ctx, a.sshConfig, a.sshLocalPort, rule.HostFile, rule.GuestFile); err != nil {
@@ -605,6 +622,11 @@ func (a *HostAgent) processGuestAgentEvents(ctx context.Context, client guestage
605622
if err != nil {
606623
return err
607624
}
625+
logrus.Info("Guest agent is running")
626+
infoTime := time.Now()
627+
a.guestAgentAliveMu.Lock()
628+
a.guestAgentAlive = &infoTime
629+
a.guestAgentAliveMu.Unlock()
608630

609631
logrus.Debugf("guest agent info: %+v", info)
610632

pkg/hostagent/requirements.go

-35
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)