diff options
author | Lamont Granquist <lamont@scriptkiddie.org> | 2014-11-04 16:39:23 -0800 |
---|---|---|
committer | Lamont Granquist <lamont@scriptkiddie.org> | 2014-11-08 11:26:07 -0800 |
commit | 550cbad4aea1554159aba59c5c310d5a6180bd60 (patch) | |
tree | 70f16a7c91993ee9f48660e6ca6d4a82b47aaa7d | |
parent | 4aba8b23a6248e34aca75436ad142836fe2d4c82 (diff) | |
download | chef-550cbad4aea1554159aba59c5c310d5a6180bd60.tar.gz |
syntax fixes for grepping output
-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 |