diff options
author | sersut <serdar@opscode.com> | 2013-10-28 15:23:56 -0700 |
---|---|---|
committer | sersut <serdar@opscode.com> | 2013-10-28 15:23:56 -0700 |
commit | 0747fb6c397c7627b9720e600da6d1940e6cbc9c (patch) | |
tree | ac9075315a30b6cfd2d869044ad04cbab10a1b51 | |
parent | dd1b9a4b8c7daf533778bd8d1b5f884ce5edc47e (diff) | |
download | chef-0747fb6c397c7627b9720e600da6d1940e6cbc9c.tar.gz |
Adapt windows_service to be compatible with win32-service 0.8.2.
This fix ensures that service waits for chef client run to end if there is one in flight when the service is shutting down. It also makes service exit cleanly when there is no chef client run in flight.
-rw-r--r-- | lib/chef/application/windows_service.rb | 30 |
1 files changed, 23 insertions, 7 deletions
diff --git a/lib/chef/application/windows_service.rb b/lib/chef/application/windows_service.rb index 08403c7aa2..4c99e50b0e 100644 --- a/lib/chef/application/windows_service.rb +++ b/lib/chef/application/windows_service.rb @@ -105,6 +105,10 @@ class Chef end end + # Daemon class needs to have all the signal callbacks return + # before service_main returns. + Chef::Log.debug("Giving signal callbacks some time to exit...") + sleep 1 Chef::Log.debug("Exiting service...") end @@ -113,15 +117,27 @@ class Chef ################################################################################ def service_stop + run_warning_displayed = false Chef::Log.info("STOP request from operating system.") - if @service_action_mutex.try_lock - @service_signal.signal - @service_action_mutex.unlock - Chef::Log.info("Service is stopping....") - else - Chef::Log.info("Currently a chef-client run is happening.") - Chef::Log.info("Service will stop once it's completed.") + loop do + # See if a run is in flight + if @service_action_mutex.try_lock + # Run is not in flight. Wake up service_main to exit. + @service_signal.signal + @service_action_mutex.unlock + break + else + unless run_warning_displayed + Chef::Log.info("Currently a chef run is happening on this system.") + Chef::Log.info("Service will stop when run is completed.") + run_warning_displayed = true + end + + Chef::Log.debug("Waiting for chef-client run...") + sleep 1 + end end + Chef::Log.info("Service is stopping....") end def service_pause |