加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > Windows > 正文

使用puppet exec检测是否已安装Windows服务

发布时间:2020-12-14 05:31:53 所属栏目:Windows 来源:网络整理
导读:我有下面的exec资源,用于安装窗口服务. 我希望它只在未安装窗口服务时执行.所以我使用onlyif命令,但命令不起作用.它一直在运行安装: exec { "install-${target_path}/${binary_name}": command = "${installUtil_filepath} /i /servicename="${service_nam
我有下面的exec资源,用于安装窗口服务.

我希望它只在未安装窗口服务时执行.所以我使用onlyif命令,但命令不起作用.它一直在运行安装:

exec { "install-${target_path}/${binary_name}":
    command   => "${installUtil_filepath} /i /servicename="${service_name}" /displayname="${display_name}" /description="${description}" "${target_path}${binary_name}"",onlyif    => "if((Get-Service "${service_name}" -ErrorAction SilentContinue).DisplayName -eq  ${display_name}) { exit 1 } else { exit 0 }",logoutput => true,provider => powershell,}

这很有效

if(Get-Service "${service_name}") { exit 1 } else { exit 0 }

解决方法

为什么首先使用服务名称检索服务,然后比较显示名称?你可以省略那个检查……

此外,您是否要在安装服务时退出0,否则使用1?

试试这个:

onlyif    => "if(Get-Service ${service_name}) { exit 0 } else { exit 1 }",

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读