Skip to content

Commit

Permalink
winsw status update
Browse files Browse the repository at this point in the history
  • Loading branch information
et-nik committed Feb 22, 2024
1 parent 0948be2 commit 40e19a8
Showing 1 changed file with 26 additions and 1 deletion.
27 changes: 26 additions & 1 deletion internal/processmanager/winsw.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"fmt"
"io"
"os"
"os/exec"
"os/user"
"path/filepath"
"strconv"
Expand Down Expand Up @@ -64,8 +65,32 @@ func (pm *WinSW) Restart(ctx context.Context, server *domain.Server, out io.Writ
return pm.command(ctx, server, "restart", out)
}

const (
exitCodeStatusNotActive = 0
exitCodeStatusActive = 1
)

func (pm *WinSW) Status(ctx context.Context, server *domain.Server, out io.Writer) (domain.Result, error) {
return pm.command(ctx, server, "status", out)
var exitErr *exec.ExitError
_, err := pm.runWinSWCommand(ctx, "status", server)
if err != nil && !errors.As(err, &exitErr) {
return domain.ErrorResult, errors.Wrap(err, "failed to get daemon status")
}
if err != nil {
return domain.ErrorResult, errors.WithMessage(err, "failed to exec command")
}

if exitErr != nil {
if exitErr.ExitCode() == exitCodeStatusNotActive {
return domain.ErrorResult, nil
}

if exitErr.ExitCode() != exitCodeStatusActive {
return domain.SuccessResult, nil
}
}

return domain.SuccessResult, nil
}

func (pm *WinSW) runWinSWCommand(ctx context.Context, command string, server *domain.Server) (domain.Result, error) {
Expand Down

0 comments on commit 40e19a8

Please sign in to comment.