From 60dcbae4c5077ea15165321baa67539120591af1 Mon Sep 17 00:00:00 2001 From: Blake Rouse Date: Mon, 16 Nov 2020 09:52:11 -0500 Subject: [PATCH] Fix issue with systemd inactive status. (#243) --- service_systemd_linux.go | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/service_systemd_linux.go b/service_systemd_linux.go index 3ce78bf..bfb7a99 100644 --- a/service_systemd_linux.go +++ b/service_systemd_linux.go @@ -249,7 +249,17 @@ func (s *systemd) Status() (Status, error) { case strings.HasPrefix(out, "active"): return StatusRunning, nil case strings.HasPrefix(out, "inactive"): - return StatusStopped, nil + // inactive can also mean its not installed, check unit files + exitCode, out, err := runWithOutput("systemctl", "list-unit-files", "-t", "service", s.Name) + if exitCode == 0 && err != nil { + return StatusUnknown, err + } + if strings.Contains(out, s.Name) { + // unit file exists, installed but not running + return StatusStopped, nil + } + // no unit file + return StatusUnknown, ErrNotInstalled case strings.HasPrefix(out, "activating"): return StatusRunning, nil case strings.HasPrefix(out, "failed"):