From b0b4cbb774beff7738b8957c731de3b9ff7bc8ce Mon Sep 17 00:00:00 2001 From: Ilya Zuyev Date: Tue, 15 Jun 2021 15:01:27 -0700 Subject: [PATCH 1/2] Do not return an error from Systemd.ForceStop(svc) if svc is already stoppedf --- pkg/minikube/sysinit/systemd.go | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/pkg/minikube/sysinit/systemd.go b/pkg/minikube/sysinit/systemd.go index 51985d557109..bad7a1d6d33c 100644 --- a/pkg/minikube/sysinit/systemd.go +++ b/pkg/minikube/sysinit/systemd.go @@ -19,7 +19,9 @@ package sysinit import ( "errors" + "fmt" "os/exec" + "strings" "k8s.io/minikube/pkg/minikube/assets" ) @@ -123,7 +125,14 @@ func (s *Systemd) Stop(svc string) error { // ForceStop terminates a service with prejudice func (s *Systemd) ForceStop(svc string) error { - _, err := s.r.RunCmd(exec.Command("sudo", "systemctl", "stop", "-f", svc)) + rr, err := s.r.RunCmd(exec.Command("sudo", "systemctl", "stop", "-f", svc)) + if err == nil { + return nil + } + if strings.Contains(rr.Output(), fmt.Sprintf("Unit %s.service not loaded", svc)) { + // already stopped + return nil + } return err } From 654a963b2f62946ff1f327fa085794a1c15886bc Mon Sep 17 00:00:00 2001 From: Ilya Zuyev Date: Mon, 21 Jun 2021 21:49:28 -0700 Subject: [PATCH 2/2] fix error processing --- pkg/minikube/sysinit/systemd.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pkg/minikube/sysinit/systemd.go b/pkg/minikube/sysinit/systemd.go index bad7a1d6d33c..16970d2ebb20 100644 --- a/pkg/minikube/sysinit/systemd.go +++ b/pkg/minikube/sysinit/systemd.go @@ -129,7 +129,7 @@ func (s *Systemd) ForceStop(svc string) error { if err == nil { return nil } - if strings.Contains(rr.Output(), fmt.Sprintf("Unit %s.service not loaded", svc)) { + if strings.Contains(rr.Output(), fmt.Sprintf("Unit %s not loaded", svc)) { // already stopped return nil }