diff options
| author | Nick Lewis <nick@puppetlabs.com> | 2011-07-26 16:45:07 -0700 |
|---|---|---|
| committer | Nick Lewis <nick@puppetlabs.com> | 2011-07-26 16:45:07 -0700 |
| commit | 1809b40e5ab05ceac166d5271cf1fe392efee1e1 (patch) | |
| tree | 81e97f0be161ba016f1bf9a64bbffead2beb8efe /lib | |
| parent | 5b167eba2b602f5c6c6c224790fa1eb56b239ad4 (diff) | |
| parent | 12d0018f93e5a72a728c6decffb351a693a86344 (diff) | |
| download | puppet-1809b40e5ab05ceac166d5271cf1fe392efee1e1.tar.gz puppet-1809b40e5ab05ceac166d5271cf1fe392efee1e1.tar.xz puppet-1809b40e5ab05ceac166d5271cf1fe392efee1e1.zip | |
Merge branch 'ticket/master/8272'
Diffstat (limited to 'lib')
| -rw-r--r-- | lib/puppet/provider/service/windows.rb | 27 |
1 files changed, 18 insertions, 9 deletions
diff --git a/lib/puppet/provider/service/windows.rb b/lib/puppet/provider/service/windows.rb index 09754ffda..f1485f268 100644 --- a/lib/puppet/provider/service/windows.rb +++ b/lib/puppet/provider/service/windows.rb @@ -41,16 +41,16 @@ 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), 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 @@ -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}" ) @@ -84,7 +97,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 +105,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 |
