summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndrew Brown <andrew.brown@shopify.com>2016-05-27 22:31:28 -0400
committerAndrew Brown <andrew.brown@shopify.com>2016-05-27 23:07:25 -0400
commitbb640efa12ac8843658fc45bba9ea70bd15e8221 (patch)
treeda02469e6b958bcc79cb18a86bc152f070375665
parenta3a22771bef2acec5c325751622a47f733ee100c (diff)
downloadchef-bb640efa12ac8843658fc45bba9ea70bd15e8221.tar.gz
Avoid Errno::EBUSY on docker containers
This commit fixes https://github.com/chef/chef/issues/4949 by adding ohai-based docker detection code and statically checking for /etc/hostname or /etc/resolv.conf.
-rw-r--r--lib/chef/provider/file.rb14
1 files changed, 13 insertions, 1 deletions
diff --git a/lib/chef/provider/file.rb b/lib/chef/provider/file.rb
index 7f85085eeb..8b3884f710 100644
--- a/lib/chef/provider/file.rb
+++ b/lib/chef/provider/file.rb
@@ -67,7 +67,13 @@ class Chef
def initialize(new_resource, run_context)
@content_class ||= Chef::Provider::File::Content
if new_resource.respond_to?(:atomic_update)
- @deployment_strategy = Chef::FileContentManagement::Deploy.strategy(new_resource.atomic_update)
+ # Resolves https://github.com/chef/chef/issues/4949
+ if docker_guest?(run_context.node) && (new_resource.path == "/etc/resolv.conf" ||
+ new_resource.path == "/etc/hostname")
+ @deployment_strategy = Chef::FileContentManagement::Deploy.strategy(false)
+ else
+ @deployment_strategy = Chef::FileContentManagement::Deploy.strategy(new_resource.atomic_update)
+ end
end
super
end
@@ -193,6 +199,12 @@ class Chef
private
+ # Return true if we are running in a docker guest, or false otherwise.
+ def docker_guest?(node)
+ node[:virtualization] && node[:virtualization][:systems] &&
+ node[:virtualization][:systems][:docker] && node[:virtualization][:systems][:docker] == "guest"
+ end
+
# What to check in this resource to see if we're going to be actively managing
# content (for things like doing checksums in load_current_resource). Expected to
# be overridden in subclasses.