summaryrefslogtreecommitdiff
path: root/lib/chef/platform
diff options
context:
space:
mode:
authorLamont Granquist <lamont@scriptkiddie.org>2014-11-03 12:16:38 -0800
committerLamont Granquist <lamont@scriptkiddie.org>2014-11-08 11:24:36 -0800
commit73302b061284f485c9ec67cc17badc48269dc094 (patch)
tree0f4436c6eb27b67ffa29c6d2a4dc76b2fbc07acb /lib/chef/platform
parent161df7e0fc6fc2f5fa4377209d5013c7b5457d6e (diff)
downloadchef-73302b061284f485c9ec67cc17badc48269dc094.tar.gz
extract which to a mixin, use for systemctl
Diffstat (limited to 'lib/chef/platform')
-rw-r--r--lib/chef/platform/service_helpers.rb15
1 files changed, 12 insertions, 3 deletions
diff --git a/lib/chef/platform/service_helpers.rb b/lib/chef/platform/service_helpers.rb
index e603591bce..4b7c27b8de 100644
--- a/lib/chef/platform/service_helpers.rb
+++ b/lib/chef/platform/service_helpers.rb
@@ -18,6 +18,7 @@
# XXX: mixing shellout into a mixin into classes has to be code smell
require 'chef/mixin/shell_out'
+require 'chef/mixin/which'
class Chef
class Platform
@@ -25,6 +26,7 @@ class Chef
class << self
include Chef::Mixin::ShellOut
+ include Chef::Mixin::Which
# This helper is mostly used to sort out the mess of different
# linux mechanisms that can be used to start services. It does
@@ -102,8 +104,15 @@ class Chef
private
+ def systemctl_path
+ if @systemctl_path.nil?
+ @systemctl_path = which("systemctl")
+ end
+ @systemctl_path
+ end
+
def systemd_sanity_check?
- ::File.exist?("/bin/systemctl") && File.exist?("/proc/1/comm") && File.open("/proc/1/comm").gets.chomp == "systemd"
+ systemctl_path && File.exist?("/proc/1/comm") && File.open("/proc/1/comm").gets.chomp == "systemd"
end
def extract_systemd_services(command)
@@ -117,8 +126,8 @@ class Chef
end
def platform_has_systemd_unit?(service_name)
- services = extract_systemd_services("systemctl --all") +
- extract_systemd_services("systemctl list-unit-files")
+ services = extract_systemd_services("#{systemctl_path} --all") +
+ extract_systemd_services("#{systemctl_path} list-unit-files")
services.include?(service_name)
rescue Mixlib::ShellOut::ShellCommandFailed
false