summaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorNick Lewis <nick@puppetlabs.com>2011-07-26 15:59:45 -0700
committerJacob Helwig <jacob@puppetlabs.com>2011-08-19 13:52:57 -0700
commit28b16584d13399f911577a47a355e866d8601085 (patch)
treecee8c2dfe8b1fcbda3f22c104a28c38b2608d65f /lib
parentc69baf63bac4e7f6296b81fcb5278eaf95e7f74b (diff)
downloadpuppet-28b16584d13399f911577a47a355e866d8601085.tar.gz
puppet-28b16584d13399f911577a47a355e866d8601085.tar.xz
puppet-28b16584d13399f911577a47a355e866d8601085.zip
(#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 <jacob@puppetlabs.com> (cherry picked from commit 12d0018f93e5a72a728c6decffb351a693a86344)
Diffstat (limited to 'lib')
-rw-r--r--lib/puppet/provider/service/windows.rb13
1 files changed, 13 insertions, 0 deletions
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}" )