diff options
Diffstat (limited to 'lib/chef/resource/windows_service.rb')
-rw-r--r-- | lib/chef/resource/windows_service.rb | 105 |
1 files changed, 33 insertions, 72 deletions
diff --git a/lib/chef/resource/windows_service.rb b/lib/chef/resource/windows_service.rb index bcd0272b06..1c7c61320f 100644 --- a/lib/chef/resource/windows_service.rb +++ b/lib/chef/resource/windows_service.rb @@ -17,7 +17,6 @@ # require "chef/resource/service" -require "chef/win32_service_constants" class Chef class Resource @@ -25,13 +24,6 @@ class Chef # # @since 12.0 class WindowsService < Chef::Resource::Service - include Chef::Win32ServiceConstants - - ALLOWED_START_TYPES = { - :automatic => SERVICE_AUTO_START, - :manual => SERVICE_DEMAND_START, - :disabled => SERVICE_DISABLED, - } # Until #1773 is resolved, you need to manually specify the windows_service resource # to use action :configure_startup and attribute startup_type @@ -39,75 +31,44 @@ class Chef provides :windows_service, os: "windows" provides :service, os: "windows" - allowed_actions :configure_startup, :create, :delete, :configure + allowed_actions :configure_startup identity_attr :service_name state_attrs :enabled, :running - property :service_name, name_property: true - - # The display name to be used by user interface programs to identify the - # service. This string has a maximum length of 256 characters. - property :display_name, String, regex: /^.{1,256}$/ - - # https://github.com/djberg96/win32-service/blob/ffi/lib/win32/windows/constants.rb#L19-L29 - property :desired_access, Integer, default: SERVICE_ALL_ACCESS - - # https://github.com/djberg96/win32-service/blob/ffi/lib/win32/windows/constants.rb#L31-L41 - property :service_type, Integer, default: SERVICE_WIN32_OWN_PROCESS - - # Valid options: - # - :automatic - # - :manual - # - :disabled - # Reference: https://github.com/djberg96/win32-service/blob/ffi/lib/win32/windows/constants.rb#L49-L54 - property :startup_type, Integer, default: SERVICE_AUTO_START, coerce: proc { |x| - if x.is_a?(Integer) - x - elsif x.is_a?(String) or x.is_a?(Symbol) - x = x.to_sym - ALLOWED_START_TYPES.fetch(x) do - Chef::Log.warn("Unsupported startup_type #{x}, falling back to :automatic") - SERVICE_AUTO_START - end - end - } - - # This only applies if startup_type is :automatic - property :delayed_start, [Integer], default: false, coerce: proc { |x| - if x.is_a?(TrueClass) - 1 - elsif x.is_a?(FalseClass) - 0 - elsif x.is_a?(Integer) - x.zero? ? 0 : 1 - end - } - - # https://github.com/djberg96/win32-service/blob/ffi/lib/win32/windows/constants.rb#L43-L47 - property :error_control, Integer, default: SERVICE_ERROR_NORMAL - - # The fully qualified path to the service binary file. The path can also - # include arguments for an auto-start service. - property :binary_path_name, String, required: true - - # The names of the load ordering group of which this service is a member. - # Specify nil or an empty string if the service does not belong to a group. - property :load_order_group, String - - # A pointer to a double null-terminated array of null-separated names of - # services or load ordering groups that the system must start before this - # service. Specify nil or an empty string if the service has no - # dependencies. Dependency on a group means that this service can run if - # at least one member of the group is running after an attempt to start - # all members of the group. - property :dependencies, [String, Array] - - property :description, String - - property :run_as_user, String, default: 'LocalSystem' - property :run_as_password, String, default: '' + def initialize(name, run_context = nil) + super + @startup_type = :automatic + @run_as_user = "" + @run_as_password = "" + 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, :disabled ] + ) + end + + def run_as_user(arg = nil) + set_or_return( + :run_as_user, + arg, + :kind_of => [ String ] + ) + end + + def run_as_password(arg = nil) + set_or_return( + :run_as_password, + arg, + :kind_of => [ String ] + ) + end end end end |