summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLamont Granquist <lamont@scriptkiddie.org>2014-11-03 12:04:53 -0800
committerLamont Granquist <lamont@scriptkiddie.org>2014-11-08 11:24:36 -0800
commit161df7e0fc6fc2f5fa4377209d5013c7b5457d6e (patch)
tree467f33e933fd22a2bc85941d4745dfa33c31b083
parent22419b1e88c42b5aeec6dc3d063b23a9cf357751 (diff)
downloadchef-161df7e0fc6fc2f5fa4377209d5013c7b5457d6e.tar.gz
correct list-unit-files + refactoring
-rw-r--r--lib/chef/platform/service_helpers.rb9
1 files changed, 6 insertions, 3 deletions
diff --git a/lib/chef/platform/service_helpers.rb b/lib/chef/platform/service_helpers.rb
index 4d4f512d6c..e603591bce 100644
--- a/lib/chef/platform/service_helpers.rb
+++ b/lib/chef/platform/service_helpers.rb
@@ -106,16 +106,19 @@ class Chef
::File.exist?("/bin/systemctl") && File.exist?("/proc/1/comm") && File.open("/proc/1/comm").gets.chomp == "systemd"
end
- def extract_systemd_services(output)
+ 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] }
# this splits off the suffix after the last dot to return "sshd"
services += services.map { |s| s.sub(/(.*)\..*/, '\1') }
+ rescue Mixlib::ShellOut::ShellCommandFailed
+ false
end
def platform_has_systemd_unit?(service_name)
- services = extract_systemd_services(shell_out!("systemctl --all").stdout) +
- extract_systemd_services(shell_out!("systemctl --list-unit-files").stdout)
+ services = extract_systemd_services("systemctl --all") +
+ extract_systemd_services("systemctl list-unit-files")
services.include?(service_name)
rescue Mixlib::ShellOut::ShellCommandFailed
false