From 1a4714d7146fa85240a1ff4ef7451df719e0b4f0 Mon Sep 17 00:00:00 2001 From: nexustar Date: Fri, 23 Sep 2022 19:25:42 +0800 Subject: [PATCH] cluster: fix service check (#2047) --- pkg/cluster/operation/check.go | 4 ++-- pkg/cluster/operation/systemd.go | 7 +++---- 2 files changed, 5 insertions(+), 6 deletions(-) diff --git a/pkg/cluster/operation/check.go b/pkg/cluster/operation/check.go index 1df971c49d..5d6d43fe5c 100644 --- a/pkg/cluster/operation/check.go +++ b/pkg/cluster/operation/check.go @@ -530,12 +530,12 @@ func CheckServices(ctx context.Context, e ctxt.Executor, host, service string, d switch disable { case false: - if !strings.Contains(active, "running") { + if active != "active" { result.Err = fmt.Errorf("service %s is not running", service) result.Msg = fmt.Sprintf("start %s.service", service) } case true: - if strings.Contains(active, "running") { + if active == "active" { result.Err = fmt.Errorf("service %s is running but should be stopped", service) result.Msg = fmt.Sprintf("stop %s.service", service) } diff --git a/pkg/cluster/operation/systemd.go b/pkg/cluster/operation/systemd.go index 7c3cd661af..497d05db22 100644 --- a/pkg/cluster/operation/systemd.go +++ b/pkg/cluster/operation/systemd.go @@ -40,10 +40,9 @@ func GetServiceStatus(ctx context.Context, e ctxt.Executor, name string) (active Action: "status", } systemd := module.NewSystemdModule(c) - stdout, _, err := systemd.Execute(ctx, e) - if err != nil { - return - } + // ignore error since stopped service returns exit code 3 + stdout, _, _ := systemd.Execute(ctx, e) + lines := strings.Split(string(stdout), "\n") for _, line := range lines { words := strings.Split(strings.TrimSpace(line), " ")