如何安装服务并启动服务如果安装,则如果安装并在chef中为Windows启动服务

时间:2017-02-23 09:11:44

标签: chef action

如何安装服务并启动服务(如果已安装,如果安装并在chef中为Windows启动服务

if service "VigilEntAgent" 
 supports :status => false then 
 package 'VigilEntAgent' do
source 'xxx'
 action :install
end
else 
 service "VigilEntAgent" do
 action :start
end

2 个答案:

答案 0 :(得分:0)

如果使用

安装了Windows服务,您可以检查
::Win32::Service.exists?( '<service_name>' )

但是如果使用package资源来安装服务,很可能只需要为package资源提供正确的名称。您在控制面板\所有控制面板项目\程序和功能中看到的那个。 Chef会检查已安装的软件包,不会再尝试安装它。

答案 1 :(得分:0)

厨师是幂等的,你应该做的是:

package 'VigilEntAgent' do  
  source 'xxx'   
  action :install  
end   

windows_service "VigilEntAgent"   
  action :start
end

服务名称必须与Windows服务管理器中的服务短名称匹配,该服务短名称将与NET START一起使用,以从命令行IIRC启动它。

自主厨12以来windows_service资源可用。

资源文档在这里:https://docs.chef.io/resources.html

相关问题