diff options
-rw-r--r-- | lib/chef/platform/service_helpers.rb | 8 |
1 files changed, 6 insertions, 2 deletions
diff --git a/lib/chef/platform/service_helpers.rb b/lib/chef/platform/service_helpers.rb index 4b7c27b8de..dc0a808c06 100644 --- a/lib/chef/platform/service_helpers.rb +++ b/lib/chef/platform/service_helpers.rb @@ -118,9 +118,13 @@ class Chef def extract_systemd_services(command) output = shell_out!(command).stdout # first line finds e.g. "sshd.service" - services = output.lines.split.map { |l| l.split[0] } + services = [] + output.each_line do |line| + fields = line.split + services << fields[0] if fields[1] == "loaded" || fields[1] == "not-found" + end # this splits off the suffix after the last dot to return "sshd" - services += services.map { |s| s.sub(/(.*)\..*/, '\1') } + services += services.select {|s| s.match(/\.service$/) }.map { |s| s.sub(/(.*)\.service$/, '\1') } rescue Mixlib::ShellOut::ShellCommandFailed false end |