diff options
author | Matt <code@deployable.org> | 2013-12-05 13:01:10 +0000 |
---|---|---|
committer | Matt <code@deployable.org> | 2013-12-05 13:01:10 +0000 |
commit | c9ba5a629e88cf51af240c711befbc1d093367ad (patch) | |
tree | 3f7c171e4e412ccc4cd8fbb22eb8246505fec616 /lib | |
parent | ecbc917ac5496f3138b798332ea66f477c33f8ba (diff) | |
download | chef-c9ba5a629e88cf51af240c711befbc1d093367ad.tar.gz |
CHEF-4791 Add more windows service states to the start/stop control flow
http://msdn.microsoft.com/en-us/library/windows/desktop/ee126211(v=vs.85).aspx
Diffstat (limited to 'lib')
-rw-r--r-- | lib/chef/provider/service/windows.rb | 36 |
1 files changed, 30 insertions, 6 deletions
diff --git a/lib/chef/provider/service/windows.rb b/lib/chef/provider/service/windows.rb index ba51e53bed..f4aa28999e 100644 --- a/lib/chef/provider/service/windows.rb +++ b/lib/chef/provider/service/windows.rb @@ -28,11 +28,19 @@ class Chef::Provider::Service::Windows < Chef::Provider::Service include Chef::Mixin::ShellOut - RUNNING = 'running' - STOPPED = 'stopped' + #Win32::Service.get_start_type AUTO_START = 'auto start' DISABLED = 'disabled' + #Win32::Service.get_current_state + RUNNING = 'running' + STOPPED = 'stopped' + CONTINUE_PENDING = 'continue pending' + PAUSE_PENDING = 'pause pending' + PAUSED = 'paused' + START_PENDING = 'start pending' + STOP_PENDING = 'stop pending' + def whyrun_supported? false end @@ -49,9 +57,15 @@ class Chef::Provider::Service::Windows < Chef::Provider::Service def start_service if Win32::Service.exists?(@new_resource.service_name) - if current_state == RUNNING + state = current_state + if state == RUNNING Chef::Log.debug "#{@new_resource} already started - nothing to do" - else + elsif state == START_PENDING + Chef::Log.debug "#{@new_resource} already sent start signal - waiting for start" + spawn_command_thread do + wait_for_state(RUNNING) + end + elsif state == STOPPED if @new_resource.start_command Chef::Log.debug "#{@new_resource} starting service using the given start_command" shell_out!(@new_resource.start_command) @@ -62,6 +76,8 @@ class Chef::Provider::Service::Windows < Chef::Provider::Service end end @new_resource.updated_by_last_action(true) + else + raise Chef::Exceptions::Service, "Service #{@new_resource} can't be started from state [#{current_state}]" end else Chef::Log.debug "#{@new_resource} does not exist - nothing to do" @@ -70,7 +86,8 @@ class Chef::Provider::Service::Windows < Chef::Provider::Service def stop_service if Win32::Service.exists?(@new_resource.service_name) - if current_state == RUNNING + state = current_state + if state == RUNNING if @new_resource.stop_command Chef::Log.debug "#{@new_resource} stopping service using the given stop_command" shell_out!(@new_resource.stop_command) @@ -81,8 +98,15 @@ class Chef::Provider::Service::Windows < Chef::Provider::Service end end @new_resource.updated_by_last_action(true) + elsif state == STOPPED + Chef::Log.debug "#{@new_resource} already stopped - nothing to do" + elsif state == STOP_PENDING + Chef::Log.debug "#{@new_resource} already sent stop signal - waiting for stop" + spawn_command_thread do + wait_for_state(STOPPED) + end else - Chef::Log.debug "#{@new_resource} already stopped - nothing to do" + raise Chef::Exceptions::Service, "Service #{@new_resource} can't be stopped from state [#{current_state}]" end else Chef::Log.debug "#{@new_resource} does not exist - nothing to do" |