Chef: How to check if the service is installed?

In the recipe, I want to check if the service is installed, and if it does not notify about the three resources required to install it. I tried a service resource that correctly identifies the service when it is installed, but throws an exception if the service is not installed.

I'm not sure which action to use here: nothing passes the resource so that it will ever be executed, but any other action will be erroneous when they try to act on a service that does not exist.

How to determine if a service is installed and is it based on this information?

I work on Windows if necessary.

+6
source share
1 answer

See how a service is defined for windows

https://github.com/opscode/chef/blob/master/lib/chef/provider/service/windows.rb

AFAIU its pretty hard to add import to your recipe:

require 'win32/service' 

and then you can check if the service exists with

 Win32::Service.exists?(@new_resource.service_name) 

voila - you can put the impediment in the library (http://docs.opscodecode/essentials_cookbook_libraries.html) so as not to pollute the recipe code and have a simple service_exists method ?.

+8
source

Source: https://habr.com/ru/post/958596/


All Articles