fix: check if initsystem service exists

when detecting whether a service exists, if it does not, the output result will be like "Unit noneexists.service could not be found." on ubuntu:20.04
This commit is contained in:
fengxsong
2023-09-08 11:15:07 +08:00
committed by GitHub
parent fba0802836
commit a69f56e137

View File

@@ -125,7 +125,7 @@ func (sysd SystemdInitSystem) ServiceExists(service string) bool {
args := []string{"status", service}
outBytes, _ := exec.Command("systemctl", args...).Output()
output := string(outBytes)
return !strings.Contains(output, "Loaded: not-found")
return !strings.Contains(output, "Loaded: not-found") && !strings.Contains(output, "could not be found")
}
// ServiceIsEnabled ensures the service is enabled to start on each boot.