diff --git a/lib/autoupdate/agent/process.go b/lib/autoupdate/agent/process.go index a24b4605e1924..75aa7cdbb9da0 100644 --- a/lib/autoupdate/agent/process.go +++ b/lib/autoupdate/agent/process.go @@ -330,12 +330,28 @@ func (s SystemdService) IsPresent(ctx context.Context) (bool, error) { // checkSystem returns an error if the system is not compatible with this process manager. func (s SystemdService) checkSystem(ctx context.Context) error { - _, err := os.Stat("/run/systemd/system") - if errors.Is(err, os.ErrNotExist) { + present, err := hasSystemD() + if err != nil { + return trace.Wrap(err) + } + if !present { s.Log.ErrorContext(ctx, "This system does not support systemd, which is required by the updater.") return trace.Wrap(ErrNotSupported) } - return trace.Wrap(err) + return nil + +} + +// hasSystemD returns true if the system uses the SystemD process manager. +func hasSystemD() (bool, error) { + _, err := os.Stat("/run/systemd/system") + if errors.Is(err, os.ErrNotExist) { + return false, nil + } + if err != nil { + return false, trace.Wrap(err) + } + return true, nil } // systemctl returns a systemctl subcommand, converting the output to logs. diff --git a/lib/autoupdate/agent/telemetry.go b/lib/autoupdate/agent/telemetry.go index a1abeb1b3d768..442d21c4f2be6 100644 --- a/lib/autoupdate/agent/telemetry.go +++ b/lib/autoupdate/agent/telemetry.go @@ -31,6 +31,13 @@ import ( // The binary is considered managed if it lives under /opt/teleport, but not within the package // path at /opt/teleport/system. func IsManagedByUpdater() (bool, error) { + systemd, err := hasSystemD() + if err != nil { + return false, trace.Wrap(err) + } + if !systemd { + return false, nil + } teleportPath, err := os.Readlink("/proc/self/exe") if err != nil { return false, trace.Wrap(err, "cannot find Teleport binary") @@ -52,6 +59,13 @@ func IsManagedByUpdater() (bool, error) { // and the default installation (with teleport.service as the unit file name). // The binary is considered managed and default if it lives within /opt/teleport/default. func IsManagedAndDefault() (bool, error) { + systemd, err := hasSystemD() + if err != nil { + return false, trace.Wrap(err) + } + if !systemd { + return false, nil + } teleportPath, err := os.Readlink("/proc/self/exe") if err != nil { return false, trace.Wrap(err, "cannot find Teleport binary")