From f7dc2d50db5e780c7c0148f8895d84a3fd0fdf3d Mon Sep 17 00:00:00 2001 From: Bryan McLellan Date: Wed, 6 Aug 2014 12:37:41 -0400 Subject: 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. --- lib/chef/resource/windows_service.rb | 50 ++++++++++++++++++++++++++++++++++++ 1 file changed, 50 insertions(+) create mode 100644 lib/chef/resource/windows_service.rb (limited to 'lib/chef/resource/windows_service.rb') 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 +# 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 -- cgit v1.2.1