From 38c181d00e87ecc699c6a3e23dd2155f716a6602 Mon Sep 17 00:00:00 2001 From: Nick Lewis Date: Tue, 26 Jul 2011 11:38:05 -0700 Subject: (#8272) Fixup logging in Windows service provider We want to use self.debug for logging in the provider, so that log messages are properly associated with the resource, rather than generically coming from Puppet. Also fix the self.instances method to not use an unnecessary extra variable when collecting. Reviewed-By: Jacob Helwig --- lib/puppet/provider/service/windows.rb | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) (limited to 'lib') diff --git a/lib/puppet/provider/service/windows.rb b/lib/puppet/provider/service/windows.rb index 09754ffda..56d56b0a9 100644 --- a/lib/puppet/provider/service/windows.rb +++ b/lib/puppet/provider/service/windows.rb @@ -41,7 +41,7 @@ Puppet::Type.type(:service).provide :windows do def enabled? w32ss = Win32::Service.config_info( @resource[:name] ) raise Puppet::Error.new("Win32 service query of #{@resource[:name]} failed" ) unless( !w32ss.nil? && w32ss.instance_of?( Struct::ServiceConfigInfo ) ) - Puppet.debug("Service #{@resource[:name]} start type is #{w32ss.start_type}") + debug("Service #{@resource[:name]} start type is #{w32ss.start_type}") case w32ss.start_type when Win32::Service.get_start_type(Win32::Service::SERVICE_AUTO_START), Win32::Service.get_start_type(Win32::Service::SERVICE_BOOT_START), @@ -84,7 +84,7 @@ Puppet::Type.type(:service).provide :windows do else raise Puppet::Error.new("Unknown service state '#{w32ss.current_state}' for service '#{@resource[:name]}'") end - Puppet.debug("Service #{@resource[:name]} is #{w32ss.current_state}") + debug("Service #{@resource[:name]} is #{w32ss.current_state}") return state rescue Win32::Service::Error => detail raise Puppet::Error.new("Cannot get status of #{@resource[:name]}, error was: #{detail}" ) @@ -92,10 +92,6 @@ Puppet::Type.type(:service).provide :windows do # returns all providers for all existing services and startup state def self.instances - srvcs = [] - Win32::Service.services.collect{ |s| - srvcs << new(:name => s.service_name) - } - srvcs + Win32::Service.services.collect { |s| new(:name => s.service_name) } end end -- cgit From 44e2d494f499e2005c1b31b92b97834189d4224d Mon Sep 17 00:00:00 2001 From: Nick Lewis Date: Tue, 26 Jul 2011 15:58:31 -0700 Subject: (#8272) Use symbols instead of booleans for enabled property on Windows Because the enable property of the service type uses :true and :false as its valid values, rather than true and false, we need to return :true and :false from our enabled? method. Otherwise, the property was being synced every time it was enabled or disabled, regardless of whether it was actually in sync or not. Reviewed-By: Jacob Helwig --- lib/puppet/provider/service/windows.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'lib') diff --git a/lib/puppet/provider/service/windows.rb b/lib/puppet/provider/service/windows.rb index 56d56b0a9..d77f3b44a 100644 --- a/lib/puppet/provider/service/windows.rb +++ b/lib/puppet/provider/service/windows.rb @@ -46,11 +46,11 @@ Puppet::Type.type(:service).provide :windows do when Win32::Service.get_start_type(Win32::Service::SERVICE_AUTO_START), Win32::Service.get_start_type(Win32::Service::SERVICE_BOOT_START), Win32::Service.get_start_type(Win32::Service::SERVICE_SYSTEM_START) - true + :true when Win32::Service.get_start_type(Win32::Service::SERVICE_DEMAND_START) :manual when Win32::Service.get_start_type(Win32::Service::SERVICE_DISABLED) - false + :false else raise Puppet::Error.new("Unknown start type: #{w32ss.start_type}") end -- cgit From 12d0018f93e5a72a728c6decffb351a693a86344 Mon Sep 17 00:00:00 2001 From: Nick Lewis Date: Tue, 26 Jul 2011 15:59:45 -0700 Subject: (#8272) Allow disabled Windows services to be started Because Windows allows a service to be both running and disabled, we now support that capability. If a service is explicitly requested to be running and disabled, we will set it to manual start if necessary, start it, and then disable it. If the service is requested to be running and enabled, we will now enable it before attempting to start it (previously, this would simply try to start it and fail). The exception to this rule is a service which is disabled, and for which we are not managing the enable property. In that case, we assume that some other authority has disabled the service, and respect that, failing to start. Thus, if the user actually wants a service to be running and disabled, they must explicitly declare that intent. Reviewed-By: Jacob Helwig --- lib/puppet/provider/service/windows.rb | 13 +++++++++++++ 1 file changed, 13 insertions(+) (limited to 'lib') diff --git a/lib/puppet/provider/service/windows.rb b/lib/puppet/provider/service/windows.rb index d77f3b44a..f1485f268 100644 --- a/lib/puppet/provider/service/windows.rb +++ b/lib/puppet/provider/service/windows.rb @@ -59,6 +59,19 @@ Puppet::Type.type(:service).provide :windows do end def start + if enabled? == :false + # If disabled and not managing enable, respect disabled and fail. + if @resource[:enable].nil? + raise Puppet::Error, "Will not start disabled service #{@resource[:name]} without managing enable. Specify 'enable => false' to override." + # Otherwise start. If enable => false, we will later sync enable and + # disable the service again. + elsif @resource[:enable] == :true + enable + else + manual_start + end + end + Win32::Service.start( @resource[:name] ) rescue Win32::Service::Error => detail raise Puppet::Error.new("Cannot start #{@resource[:name]}, error was: #{detail}" ) -- cgit