summaryrefslogtreecommitdiff
path: root/lib/chef/resource/windows_service.rb
diff options
context:
space:
mode:
authorBryan McLellan <btm@loftninjas.org>2014-08-06 12:37:41 -0400
committerBryan McLellan <btm@loftninjas.org>2014-08-12 16:51:10 -0400
commitf7dc2d50db5e780c7c0148f8895d84a3fd0fdf3d (patch)
tree93d1144ba09a8973e5214607d02c78edd9e312c7 /lib/chef/resource/windows_service.rb
parente08741f4f713c98f23e6db37426961c8c0d01b8f (diff)
downloadchef-f7dc2d50db5e780c7c0148f8895d84a3fd0fdf3d.tar.gz
CHEF-5022: Differentiate between Windows service startup_types
A Windows service startup_type can be automatic, manual, or disabled. This adds a startup_type attribute to specify automatic or manual, and defaults to automatic because we currently have no functionality to set a service to manual. This is important because if you stop a service that is automatic, Windows will change the startup_type to manual.
Diffstat (limited to 'lib/chef/resource/windows_service.rb')
-rw-r--r--lib/chef/resource/windows_service.rb50
1 files changed, 50 insertions, 0 deletions
diff --git a/lib/chef/resource/windows_service.rb b/lib/chef/resource/windows_service.rb
new file mode 100644
index 0000000000..3f207b5014
--- /dev/null
+++ b/lib/chef/resource/windows_service.rb
@@ -0,0 +1,50 @@
+#
+# Author:: Bryan McLellan <btm@loftninjas.org>
+# Copyright:: Copyright (c) 2014 Chef Software, Inc.
+# License:: Apache License, Version 2.0
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+
+require 'chef/resource/service'
+
+class Chef
+ class Resource
+ class WindowsService < Chef::Resource::Service
+
+ provides :service, :on_platforms => ["windows"]
+
+ identity_attr :service_name
+
+ state_attrs :enabled, :running
+
+ def initialize(name, run_context=nil)
+ super
+ @resource_name = :windows_service
+ @provider = Chef::Provider::Service::Windows
+ @startup_type = :automatic
+ end
+
+
+ def startup_type(arg=nil)
+ # Set-Service arguments are automatic and manual
+ # Win32::Service returns 'auto start' or 'demand start' respectively, which the provider currently uses
+ set_or_return(
+ :startup_type,
+ arg,
+ :equal_to => [ :automatic, :manual ]
+ )
+ end
+ end
+ end
+end