Skip to content

Commit

Permalink
cluster: fix service check (#2047)
Browse files Browse the repository at this point in the history
  • Loading branch information
nexustar authored Sep 23, 2022
1 parent 95b3061 commit 1a4714d
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 6 deletions.
4 changes: 2 additions & 2 deletions pkg/cluster/operation/check.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down
7 changes: 3 additions & 4 deletions pkg/cluster/operation/systemd.go
Original file line number Diff line number Diff line change
Expand Up @@ -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), " ")
Expand Down

0 comments on commit 1a4714d

Please sign in to comment.