summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCaleb Tennis <caleb.tennis@gmail.com>2012-11-29 08:22:39 -0500
committerCaleb Tennis <caleb.tennis@gmail.com>2012-11-29 08:22:39 -0500
commit706a748404107eff715b3cea16d47e89da648886 (patch)
treeeb1d0f7daa6f68223d872e63bebebe1dc6d0345c
parent70f80b20f7da71f05f9c8dc0ad9c25312f61b511 (diff)
downloadchef-706a748404107eff715b3cea16d47e89da648886.tar.gz
Add support for automatically using the Systemd service provider if it's in use
-rw-r--r--lib/chef/resource/service.rb4
-rw-r--r--spec/unit/resource/service_spec.rb14
2 files changed, 18 insertions, 0 deletions
diff --git a/lib/chef/resource/service.rb b/lib/chef/resource/service.rb
index ea43baa414..ecba29e58c 100644
--- a/lib/chef/resource/service.rb
+++ b/lib/chef/resource/service.rb
@@ -46,6 +46,10 @@ class Chef
@startup_type = :automatic
@supports = { :restart => false, :reload => false, :status => false }
@allowed_actions.push(:enable, :disable, :start, :stop, :restart, :reload)
+
+ if(run_context && run_context.node[:init_package] == "systemd")
+ @provider = Chef::Provider::Service::Systemd
+ end
end
def service_name(arg=nil)
diff --git a/spec/unit/resource/service_spec.rb b/spec/unit/resource/service_spec.rb
index c06eb9dd77..c9c3e7ce5d 100644
--- a/spec/unit/resource/service_spec.rb
+++ b/spec/unit/resource/service_spec.rb
@@ -29,6 +29,20 @@ describe Chef::Resource::Service do
@resource.should be_a_kind_of(Chef::Resource)
@resource.should be_a_kind_of(Chef::Resource::Service)
end
+
+ it "should not set a provider unless node[:init_package] is defined as systemd" do
+ @resource.provider.should == nil
+ end
+
+ it "should set the provider to Chef::Provider::Service::Systemd if node[:init_package] is systemd" do
+ node = Chef::Node.new
+ node.set[:init_package] = "systemd"
+ cookbook_collection = Chef::CookbookCollection.new([])
+ events = Chef::EventDispatch::Dispatcher.new
+ run_context = Chef::RunContext.new(node, cookbook_collection, events)
+ @resource = Chef::Resource::Service.new("chef", run_context)
+ @resource.provider.should == Chef::Provider::Service::Systemd
+ end
it "should set the service_name to the first argument to new" do
@resource.service_name.should eql("chef")