Skip to content

Commit 911cb03

Browse files
authored
[teleport-update] Remove warning when running Teleport on platforms without systemd (#51465)
* improve detection logic on non-systemd platforms * adjust * remove OS check
1 parent 4924a67 commit 911cb03

File tree

2 files changed

+33
-3
lines changed

2 files changed

+33
-3
lines changed

lib/autoupdate/agent/process.go

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -330,12 +330,28 @@ func (s SystemdService) IsPresent(ctx context.Context) (bool, error) {
330330

331331
// checkSystem returns an error if the system is not compatible with this process manager.
332332
func (s SystemdService) checkSystem(ctx context.Context) error {
333-
_, err := os.Stat("/run/systemd/system")
334-
if errors.Is(err, os.ErrNotExist) {
333+
present, err := hasSystemD()
334+
if err != nil {
335+
return trace.Wrap(err)
336+
}
337+
if !present {
335338
s.Log.ErrorContext(ctx, "This system does not support systemd, which is required by the updater.")
336339
return trace.Wrap(ErrNotSupported)
337340
}
338-
return trace.Wrap(err)
341+
return nil
342+
343+
}
344+
345+
// hasSystemD returns true if the system uses the SystemD process manager.
346+
func hasSystemD() (bool, error) {
347+
_, err := os.Stat("/run/systemd/system")
348+
if errors.Is(err, os.ErrNotExist) {
349+
return false, nil
350+
}
351+
if err != nil {
352+
return false, trace.Wrap(err)
353+
}
354+
return true, nil
339355
}
340356

341357
// systemctl returns a systemctl subcommand, converting the output to logs.

lib/autoupdate/agent/telemetry.go

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,13 @@ import (
3131
// The binary is considered managed if it lives under /opt/teleport, but not within the package
3232
// path at /opt/teleport/system.
3333
func IsManagedByUpdater() (bool, error) {
34+
systemd, err := hasSystemD()
35+
if err != nil {
36+
return false, trace.Wrap(err)
37+
}
38+
if !systemd {
39+
return false, nil
40+
}
3441
teleportPath, err := os.Readlink("/proc/self/exe")
3542
if err != nil {
3643
return false, trace.Wrap(err, "cannot find Teleport binary")
@@ -52,6 +59,13 @@ func IsManagedByUpdater() (bool, error) {
5259
// and the default installation (with teleport.service as the unit file name).
5360
// The binary is considered managed and default if it lives within /opt/teleport/default.
5461
func IsManagedAndDefault() (bool, error) {
62+
systemd, err := hasSystemD()
63+
if err != nil {
64+
return false, trace.Wrap(err)
65+
}
66+
if !systemd {
67+
return false, nil
68+
}
5569
teleportPath, err := os.Readlink("/proc/self/exe")
5670
if err != nil {
5771
return false, trace.Wrap(err, "cannot find Teleport binary")

0 commit comments

Comments
 (0)