From 541c63d737e33259e60d942eab0a182a50d476cd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20=22Pisco=22=20Fernandes?= Date: Fri, 22 Sep 2023 15:16:41 +0100 Subject: [PATCH] TUN-7824: Fix usage of systemctl status to detect which services are installed ## Summary To determine which services were installed, cloudflared, was using the command `systemctl status` this command gives an error if the service is installed but isn't running, which makes the `uninstall services` command report wrongly the services not installed. Therefore, this commit adapts it to use the `systemctl list-units` command combined with a grep to find which services are installed and need to be removed. --- cmd/cloudflared/linux_service.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cmd/cloudflared/linux_service.go b/cmd/cloudflared/linux_service.go index 72aada5e..36ae639b 100644 --- a/cmd/cloudflared/linux_service.go +++ b/cmd/cloudflared/linux_service.go @@ -369,7 +369,7 @@ func uninstallSystemd(log *zerolog.Logger) error { // Get only the installed services installedServices := make(map[string]ServiceTemplate) for serviceName, serviceTemplate := range systemdAllTemplates { - if err := runCommand("systemctl", "status", serviceName); err == nil { + if err := runCommand("systemctl", "list-units", "--all", "|", "grep", serviceName); err == nil { installedServices[serviceName] = serviceTemplate } else { log.Info().Msgf("Service '%s' not installed, skipping its uninstall", serviceName)