summaryrefslogtreecommitdiff
path: root/lib/chef/platform
diff options
context:
space:
mode:
authorLamont Granquist <lamont@scriptkiddie.org>2014-10-31 16:56:03 -0700
committerLamont Granquist <lamont@scriptkiddie.org>2014-11-08 11:24:36 -0800
commit22419b1e88c42b5aeec6dc3d063b23a9cf357751 (patch)
tree49207889a98ddbbaa4c13b637626c2fd1d130f9d /lib/chef/platform
parentc92393e52977b468bff720ae84de644da933ac03 (diff)
downloadchef-22419b1e88c42b5aeec6dc3d063b23a9cf357751.tar.gz
fix systemd for Ubuntu 14.10
It has systemctl installed on the system but does not have systemd wired up as init by default and trying to use systemctl throws exceptions that breaks everything. Also add a big banner warning because I'm sure someone is going to think that the shortest past to fixing priority bugs is hacking up what gets reported from these modules, rather than fixing the bugs in the downstream logic.
Diffstat (limited to 'lib/chef/platform')
-rw-r--r--lib/chef/platform/service_helpers.rb19
1 files changed, 16 insertions, 3 deletions
diff --git a/lib/chef/platform/service_helpers.rb b/lib/chef/platform/service_helpers.rb
index 440391843e..4d4f512d6c 100644
--- a/lib/chef/platform/service_helpers.rb
+++ b/lib/chef/platform/service_helpers.rb
@@ -31,6 +31,14 @@ class Chef
# not necessarily need to linux-specific, but currently all our
# other service providers are narrowly platform-specific with no
# alternatives.
+ #
+ # NOTE: if a system has (for example) chkconfig installed then we
+ # should report that chkconfig is installed. The fact that a system
+ # may also have systemd installed does not mean that we do not
+ # report that systemd is also installed. This module is purely for
+ # discovery of all the alternatives, handling the priority of the
+ # different services is NOT a design concern of this module.
+ #
def service_resource_providers
service_resource_providers = []
@@ -55,8 +63,7 @@ class Chef
service_resource_providers << :redhat
end
- if ::File.exist?("/bin/systemctl")
- # FIXME: look for systemd as init provider
+ if systemd_sanity_check?
service_resource_providers << :systemd
end
@@ -86,7 +93,7 @@ class Chef
configs << :usr_local_etc_rcd
end
- if ::File.exist?("/bin/systemctl") && platform_has_systemd_unit?(service_name)
+ if systemd_sanity_check? && platform_has_systemd_unit?(service_name)
configs << :systemd
end
@@ -95,6 +102,10 @@ class Chef
private
+ def systemd_sanity_check?
+ ::File.exist?("/bin/systemctl") && File.exist?("/proc/1/comm") && File.open("/proc/1/comm").gets.chomp == "systemd"
+ end
+
def extract_systemd_services(output)
# first line finds e.g. "sshd.service"
services = output.lines.split.map { |l| l.split[0] }
@@ -106,6 +117,8 @@ class Chef
services = extract_systemd_services(shell_out!("systemctl --all").stdout) +
extract_systemd_services(shell_out!("systemctl --list-unit-files").stdout)
services.include?(service_name)
+ rescue Mixlib::ShellOut::ShellCommandFailed
+ false
end
end
end