From 75d61cbf8faacd1e303f50cf136ea1cbb1ac7de4 Mon Sep 17 00:00:00 2001 From: Tim Smith Date: Fri, 24 Apr 2020 13:50:53 -0700 Subject: Move the windows only timeout property from service to windows_service Also give it a real default. This improves our automatic documentation generation. Signed-off-by: Tim Smith --- lib/chef/provider/service/windows.rb | 4 +--- lib/chef/resource/service.rb | 5 ----- lib/chef/resource/windows_service.rb | 5 +++++ 3 files changed, 6 insertions(+), 8 deletions(-) diff --git a/lib/chef/provider/service/windows.rb b/lib/chef/provider/service/windows.rb index 63cc5fd26c..9a7f5fa1d8 100644 --- a/lib/chef/provider/service/windows.rb +++ b/lib/chef/provider/service/windows.rb @@ -47,8 +47,6 @@ class Chef::Provider::Service::Windows < Chef::Provider::Service START_PENDING = "start pending".freeze STOP_PENDING = "stop pending".freeze - TIMEOUT = 60 - SERVICE_RIGHT = "SeServiceLogonRight".freeze def load_current_resource @@ -336,7 +334,7 @@ class Chef::Provider::Service::Windows < Chef::Provider::Service end def resource_timeout - @resource_timeout ||= @new_resource.timeout || TIMEOUT + @resource_timeout ||= @new_resource.timeout end def spawn_command_thread diff --git a/lib/chef/resource/service.rb b/lib/chef/resource/service.rb index 50a7dda437..b28ba365b2 100644 --- a/lib/chef/resource/service.rb +++ b/lib/chef/resource/service.rb @@ -114,11 +114,6 @@ class Chef property :priority, [ Integer, String, Hash ], description: "Debian platform only. The relative priority of the program for start and shutdown ordering. May be an integer or a Hash. An integer is used to define the start run levels; stop run levels are then 100-integer. A Hash is used to define values for specific run levels. For example, { 2 => [:start, 20], 3 => [:stop, 55] } will set a priority of twenty for run level two and a priority of fifty-five for run level three." - # timeout only applies to the windows service manager - property :timeout, Integer, - description: "Microsoft Windows platform only. The amount of time (in seconds) to wait before timing out.", - desired_state: false - property :parameters, Hash, description: "Upstart only: A hash of parameters to pass to the service command for use in the service definition." diff --git a/lib/chef/resource/windows_service.rb b/lib/chef/resource/windows_service.rb index 9d61990605..34f3cfb9a7 100644 --- a/lib/chef/resource/windows_service.rb +++ b/lib/chef/resource/windows_service.rb @@ -41,6 +41,11 @@ class Chef allowed_actions :configure_startup, :create, :delete, :configure + property :timeout, Integer, + description: "The amount of time (in seconds) to wait before timing out.", + default: 60, + desired_state: false + # The display name to be used by user interface programs to identify the # service. This string has a maximum length of 256 characters. property :display_name, String, regex: /^.{1,256}$/, -- cgit v1.2.1 From 47b9da0494e48a3695295b69435e0a346056a187 Mon Sep 17 00:00:00 2001 From: Tim Smith Date: Fri, 24 Apr 2020 13:54:24 -0700 Subject: Remove the pointless helper method Signed-off-by: Tim Smith --- lib/chef/provider/service/windows.rb | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/lib/chef/provider/service/windows.rb b/lib/chef/provider/service/windows.rb index 9a7f5fa1d8..6c1f7c3583 100644 --- a/lib/chef/provider/service/windows.rb +++ b/lib/chef/provider/service/windows.rb @@ -327,22 +327,18 @@ class Chef::Provider::Service::Windows < Chef::Provider::Service retries = 0 loop do break if current_state == desired_state - raise Timeout::Error if ( retries += 1 ) > resource_timeout + raise Timeout::Error if ( retries += 1 ) > @new_resource.timeout sleep 1 end end - def resource_timeout - @resource_timeout ||= @new_resource.timeout - end - def spawn_command_thread worker = Thread.new do yield end - Timeout.timeout(resource_timeout) do + Timeout.timeout(@new_resource.timeout) do worker.join end end -- cgit v1.2.1 From ae08a572850f247655674c8a9329566c815ca1d7 Mon Sep 17 00:00:00 2001 From: Tim Smith Date: Fri, 24 Apr 2020 14:10:52 -0700 Subject: Add back shell_out with the actual 900s default Signed-off-by: Tim Smith --- lib/chef/resource/service.rb | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/lib/chef/resource/service.rb b/lib/chef/resource/service.rb index b28ba365b2..2a55973500 100644 --- a/lib/chef/resource/service.rb +++ b/lib/chef/resource/service.rb @@ -114,6 +114,11 @@ class Chef property :priority, [ Integer, String, Hash ], description: "Debian platform only. The relative priority of the program for start and shutdown ordering. May be an integer or a Hash. An integer is used to define the start run levels; stop run levels are then 100-integer. A Hash is used to define values for specific run levels. For example, { 2 => [:start, 20], 3 => [:stop, 55] } will set a priority of twenty for run level two and a priority of fifty-five for run level three." + property :timeout, Integer, + description: "The amount of time (in seconds) to wait before timing out.", + default: 900, + desired_state: false + property :parameters, Hash, description: "Upstart only: A hash of parameters to pass to the service command for use in the service definition." -- cgit v1.2.1 From 69d6fff6f18e4c2d9e60d62853659b855c49b43e Mon Sep 17 00:00:00 2001 From: Tim Smith Date: Fri, 24 Apr 2020 14:19:01 -0700 Subject: Add specs for the timeout defaults Signed-off-by: Tim Smith --- spec/unit/resource/service_spec.rb | 4 ++++ spec/unit/resource/windows_service_spec.rb | 9 +++++++++ 2 files changed, 13 insertions(+) diff --git a/spec/unit/resource/service_spec.rb b/spec/unit/resource/service_spec.rb index 9bade1698d..a94beece6b 100644 --- a/spec/unit/resource/service_spec.rb +++ b/spec/unit/resource/service_spec.rb @@ -145,6 +145,10 @@ describe Chef::Resource::Service do expect(resource.timeout).to eql(1) end + it "defaults the timeout property to 900 (seconds)" do + expect(resource.timeout).to eql(900) + end + %w{enabled running}.each do |prop| it "accepts true for #{prop} property" do resource.send(prop, true) diff --git a/spec/unit/resource/windows_service_spec.rb b/spec/unit/resource/windows_service_spec.rb index 4f93465b19..1a35e1ad52 100644 --- a/spec/unit/resource/windows_service_spec.rb +++ b/spec/unit/resource/windows_service_spec.rb @@ -48,6 +48,15 @@ describe Chef::Resource::WindowsService, "initialize" do expect { resource.action :unmask }.not_to raise_error end + it "accepts an Integer for timeout property" do + resource.timeout 1 + expect(resource.timeout).to eql(1) + end + + it "defaults the timeout property to 60 (seconds)" do + expect(resource.timeout).to eql(60) + end + %i{automatic manual disabled}.each do |type| it "supports setting startup_type property to #{type.inspect}" do resource.startup_type type -- cgit v1.2.1