diff options
-rw-r--r-- | lib/chef/provider/service.rb | 4 | ||||
-rw-r--r-- | lib/chef/provider/service/init.rb | 4 | ||||
-rw-r--r-- | spec/unit/provider/service/init_service_spec.rb | 10 |
3 files changed, 17 insertions, 1 deletions
diff --git a/lib/chef/provider/service.rb b/lib/chef/provider/service.rb index 27af1ac970..fbf269dbec 100644 --- a/lib/chef/provider/service.rb +++ b/lib/chef/provider/service.rb @@ -163,6 +163,10 @@ class Chef end end + def custom_command_for_action?(action) + !!@new_resource.send("#{action}_command".to_sym) rescue false + end + end end end diff --git a/lib/chef/provider/service/init.rb b/lib/chef/provider/service/init.rb index 2dd03679c5..09f47e866f 100644 --- a/lib/chef/provider/service/init.rb +++ b/lib/chef/provider/service/init.rb @@ -37,7 +37,9 @@ class Chef # do not call super here, inherit only shared_requirements shared_resource_requirements requirements.assert(:start, :stop, :restart, :reload) do |a| - a.assertion { ::File.exist?(default_init_command) } + a.assertion do + custom_command_for_action?(action) || ::File.exist?(default_init_command) + end a.failure_message(Chef::Exceptions::Service, "#{default_init_command} does not exist!") a.whyrun("Init script '#{default_init_command}' doesn't exist, assuming a prior action would have created it.") do # blindly assume that the service exists but is stopped in why run mode: diff --git a/spec/unit/provider/service/init_service_spec.rb b/spec/unit/provider/service/init_service_spec.rb index 6daa62b04f..650fca8320 100644 --- a/spec/unit/provider/service/init_service_spec.rb +++ b/spec/unit/provider/service/init_service_spec.rb @@ -222,4 +222,14 @@ RUNNING_PS @provider.reload_service() end end + + describe "when a custom command has been specified" do + before do + @new_resource.start_command("/etc/init.d/chef startyousillysally") + end + + it "should still pass all why run assertions" do + lambda { @provider.run_action(:start) }.should_not raise_error(Chef::Exceptions::Service) + end + end end |