File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff 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:
You can’t perform that action at this time.
0 commit comments