Chef:如何检查是否已安装服务? [英] Chef: How do I check to see if a service is installed?

查看:81
本文介绍了Chef:如何检查是否已安装服务?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在食谱中,我想检查是否已安装服务,以及是否未通知安装该服务所需的3种资源。我尝试了服务资源,该资源可以在安装时正确识别该服务,但是如果未安装该服务,则会引发异常。

In a recipe I want to check to see if a service is installed, and if it is not notify the 3 resources needed to install it. I tried the service resource, which correctly identifies the service when it is installed, but throws an exception if the service is not installed.

我不确定在此使用什么操作。 :什么都不会跳过资源,因此它永远不会被执行,但是当其他任何操作试图对不存在的服务执行操作时,它们都会出错。

I'm not sure what action to use here. :nothing just skips the resource so it ever get executed, but any of the other actions will error when they attempt to act on a service that doesn't exist.

如何

如果相关,我正在Windows上运行。

I'm running on Windows, if that's relevant.

推荐答案

看看如何定义Windows服务

Take a look on how is service for windows is defined

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

AFAIU非常简单地将导入内容添加到您的食谱中:

AFAIU its pretty straighforward add import to your recipe:

require 'win32/service'

,然后可以检查服务是否存在

and then you can check if service exists with

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

瞧-您可以在库中添加拼写(http://docs.opscode.com/essentials_cookbook_libraries.html )只是不污染配方代码,而
具有简单的service_exists方法。

voila - you can put impementation to library (http://docs.opscode.com/essentials_cookbook_libraries.html) just not to pollute recipe code and have simple method service_exists?.

这篇关于Chef:如何检查是否已安装服务?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆