Use the windows_service resource to manage a service on the Microsoft Windows platform.
A windows_service resource block manages the state of a service on a machine that is running Microsoft Windows. For example:
windows_service 'BITS' do action :configure_startup startup_type :manual end
The full syntax for all of the properties that are available to the windows_service resource is:
windows_service 'name' do init_command String notifies # see description pattern String provider Chef::Provider::Service::Windows reload_command String restart_command String run_as_password String run_as_user String service_name String # defaults to 'name' if not specified start_command String startup_type Symbol status_command String stop_command String subscribes # see description supports Hash timeout Integer action Symbol # defaults to :nothing if not specified end
where
windows_service
is the resourcename
is the name of the resource block:action
identifies the steps the chef-client will take to bring the node into the desired stateinit_command
, pattern
, provider
, reload_command
, restart_command
, run_as_password
, run_as_user
, service_name
, start_command
, startup_type
, status_command
, stop_command
, supports
, and timeout
are properties of this resource, with the Ruby type shown. See “Properties” section below for more information about all of the properties that may be used with this resource.This resource has the following actions:
:configure_startup
startup_type
property.:disable
Disabled
startup type on the Microsoft Windows platform.:enable
Automatic
startup type on the Microsoft Windows platform.:nothing
:reload
:restart
:start
:stop
This resource has the following properties:
ignore_failure
Ruby Types: TrueClass, FalseClass
Continue running a recipe if a resource fails for any reason. Default value: false
.
init_command
Ruby Type: String
The path to the init script that is associated with the service. This is typically /etc/init.d/SERVICE_NAME
. The init_command
property can be used to prevent the need to specify overrides for the start_command
, stop_command
, and restart_command
attributes. Default value: nil
.
notifies
Ruby Type: Symbol, ‘Chef::Resource[String]’
A resource may notify another resource to take action when its state changes. Specify a 'resource[name]'
, the :action
that resource should take, and then the :timer
for that action. A resource may notifiy more than one resource; use a notifies
statement for each resource to be notified.
A timer specifies the point during the chef-client run at which a notification is run. The following timers are available:
:before
:delayed
:immediate
, :immediately
The syntax for notifies
is:
notifies :action, 'resource[name]', :timer
pattern
Ruby Type: String
The pattern to look for in the process table. Default value: service_name
.
provider
Ruby Type: Chef Class
Optional. Explicitly specifies a provider.
reload_command
Ruby Type: String
The command used to tell a service to reload its configuration.
restart_command
Ruby Type: String
The command used to restart a service.
retries
Ruby Type: Integer
The number of times to catch exceptions and retry the resource. Default value: 0
.
retry_delay
Ruby Type: Integer
The retry delay (in seconds). Default value: 2
.
run_as_password
Ruby Type: String
The password for the user specified by run_as_user
.
run_as_user
Ruby Type: String
The user under which a Microsoft Windows service runs.
service_name
Ruby Type: String
The name of the service. Default value: the name
of the resource block See “Syntax” section above for more information.
start_command
Ruby Type: String
The command used to start a service.
startup_type
Ruby Type: Symbol
Use to specify the startup type for a Microsoft Windows service. Possible values: :automatic
, :disabled
, or :manual
. Default value: :automatic
.
status_command
Ruby Type: String
The command used to check the run status for a service.
stop_command
Ruby Type: String
The command used to stop a service.
subscribes
Ruby Type: Symbol, ‘Chef::Resource[String]’
A resource may listen to another resource, and then take action if the state of the resource being listened to changes. Specify a 'resource[name]'
, the :action
to be taken, and then the :timer
for that action.
A timer specifies the point during the chef-client run at which a notification is run. The following timers are available:
:before
:delayed
:immediate
, :immediately
The syntax for subscribes
is:
subscribes :action, 'resource[name]', :timer
supports
Ruby Type: Hash
A list of properties that controls how the chef-client is to attempt to manage a service: :restart
, :reload
, :status
. For :restart
, the init script or other service provider can use a restart command; if :restart
is not specified, the chef-client attempts to stop and then start a service. For :reload
, the init script or other service provider can use a reload command. For :status
, the init script or other service provider can use a status command to determine if the service is running; if :status
is not specified, the chef-client attempts to match the service_name
against the process table as a regular expression, unless a pattern is specified as a parameter property. Default value: { :restart => false, :reload => false, :status => false }
for all platforms (except for the Red Hat platform family, which defaults to { :restart => false, :reload => false, :status => true }
.)
timeout
Ruby Type: Integer
The amount of time (in seconds) to wait before timing out. Default value: 60
.
The following examples demonstrate various approaches for using resources in recipes. If you want to see examples of how Chef uses resources in recipes, take a closer look at the cookbooks that Chef authors and maintains: https://github.com/chef-cookbooks.
Start a service manually
windows_service 'BITS' do action :configure_startup startup_type :manual end
© Chef Software, Inc.
Licensed under the Creative Commons Attribution 3.0 Unported License.
The Chef™ Mark and Chef Logo are either registered trademarks/service marks or trademarks/servicemarks of Chef, in the United States and other countries and are used with Chef Inc's permission.
We are not affiliated with, endorsed or sponsored by Chef Inc.
https://docs-archive.chef.io/release/12-13/resource_windows_service.html