Skip to content

Commit 11da47d

Browse files
committed
fix(containerd): update k3s systemd unit restart to support agent mode
Signed-off-by: Vaughn Dice <vdice@akamai.com>
1 parent e3055ee commit 11da47d

1 file changed

Lines changed: 7 additions & 3 deletions

File tree

internal/containerd/restart_unix.go

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -89,11 +89,15 @@ func (c K3sRestarter) Restart() error {
8989
// This restarter will be used both for stock K3s distros, which use systemd as well as K3d, which does not.
9090

9191
// If listing systemd units succeeds, prefer systemctl restart; otherwise kill pid
92-
if _, err := ListSystemdUnits(); err == nil {
93-
out, err := nsenterCmd("systemctl", "restart", "k3s").CombinedOutput()
92+
// First, collect systemd units to determine which k3s service to restart
93+
// TODO: It appears the service name itself can be customized, so we may want to consider similar support
94+
// See https://github.com/k3s-io/k3s/blob/main/install.sh
95+
if units, err := ListSystemdUnits(); err == nil {
96+
service := regexp.MustCompile("k3s|k3s-agent").FindString(string(units))
97+
out, err := nsenterCmd("systemctl", "restart", service).CombinedOutput()
9498
slog.Debug(string(out))
9599
if err != nil {
96-
return fmt.Errorf("unable to restart k3s: %w", err)
100+
return fmt.Errorf("unable to restart the %s systemd service: %w", service, err)
97101
}
98102
} else {
99103
// TODO: this approach still leads to the behavior mentioned in https://github.com/spinframework/runtime-class-manager/issues/140:

0 commit comments

Comments
 (0)