summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAvishai Ish-Shalom <avishai.ish-shalom@mail.huji.ac.il>2011-03-26 11:38:09 +0200
committerBryan McLellan <btm@opscode.com>2011-06-01 15:19:46 -0700
commit8e964515c6c036f513c557ae8c8b3fed9a33aa24 (patch)
tree21d2f68703e005c516aa93e0be819e3a99bbd7a5
parent139335d4aade5088844c6f785d42b477b0017ecf (diff)
downloadchef-8e964515c6c036f513c557ae8c8b3fed9a33aa24.tar.gz
Added check for supports[:restart], IMPORTANT: read below
This commit changes the default behaviour of the upstart provider. Because service resource defaults to supports[:retart] = false, unless the user explicitly define support :restart => true the provider will default to 'start servicename' & 'stop servicename' instead of 'restart servicename'. Yikes!
-rw-r--r--chef/lib/chef/provider/service/upstart.rb6
-rw-r--r--chef/spec/unit/provider/service/upstart_service_spec.rb8
2 files changed, 13 insertions, 1 deletions
diff --git a/chef/lib/chef/provider/service/upstart.rb b/chef/lib/chef/provider/service/upstart.rb
index 3497737b49..a32d67fc9a 100644
--- a/chef/lib/chef/provider/service/upstart.rb
+++ b/chef/lib/chef/provider/service/upstart.rb
@@ -140,12 +140,16 @@ class Chef
def restart_service
if @new_resource.restart_command
super
- else
+ elsif @new_resource.supports[:restart]
if @current_resource.running
run_command_with_systems_locale(:command => "/sbin/restart #{@new_resource.service_name}")
else
start_service
end
+ else
+ stop_service
+ sleep(1)
+ start_service
end
end
diff --git a/chef/spec/unit/provider/service/upstart_service_spec.rb b/chef/spec/unit/provider/service/upstart_service_spec.rb
index 82e8c58e49..88b47e6263 100644
--- a/chef/spec/unit/provider/service/upstart_service_spec.rb
+++ b/chef/spec/unit/provider/service/upstart_service_spec.rb
@@ -206,6 +206,7 @@ describe Chef::Provider::Service::Upstart do
describe "start and stop service" do
before(:each) do
+ @new_resource.supports(:restart => true)
@current_resource = Chef::Resource::Service.new('rsyslog')
Chef::Resource::Service.stub!(:new).and_return(@current_resource)
@@ -248,6 +249,13 @@ describe Chef::Provider::Service::Upstart do
@provider.restart_service()
end
+ it "should start & stop the service if @new_resource.supports[:restart] == false" do
+ @new_resource.supports(:restart => false)
+ @provider.should_receive(:stop_service).and_return(true)
+ @provider.should_receive(:start_service).and_return(true)
+ @provider.restart_service()
+ end
+
it "should call the reload command if one is specified" do
@current_resource.stub!(:running).and_return(true)
@new_resource.stub!(:reload_command).and_return("/sbin/rsyslog reloadyousillysally")