linux-puppet onlyif with pgrep不起作用

linux-puppet onlyif with pgrep不起作用,第1张

概述我想在puppet中使用exec,只要它的进程没有运行 exec { "execute me": onlyif => "pgrep -fc 'ruby execute.rb'", command => "execute me",} 所以在上面的例子中,如果进程’ruby execute.rb’已经运行,那么exec不应该运行为 pgrep -fc 'ruby execute 我想在puppet中使用exec,只要它的进程没有运行
exec { "execute me":    onlyif  => "pgrep -fc 'ruby execute.rb'",command => "execute me",}

所以在上面的例子中,如果进程’ruby execute.rb’已经运行,那么exec不应该运行为

pgrep -fc 'ruby execute.rb' will return 1.

然而

该命令似乎总是在木偶中运行.

在我的linux框中,当我执行pgrep -fc’ruby execute.rb’时,我总是得到一个大于0的值.

我的命令有问题吗?

解决方法 只有当pgrep返回0时,你的exec才会运行.pgrep手册页告诉我们,只有找到匹配的进程时,pgrep的退出代码才为零(0),当没有匹配的进程时,它将返回一(1).另一方面,puppet文档告诉我们,只有当参数中的命令返回0时,parameter onlyif才会执行资源.

而不是只有你应该使用parameter unless.这样你的exec只会在你的pgrep返回非零时运行,即.它没有找到任何匹配的过程.

exec { "execute me":  unless  => "pgrep -fc 'ruby execute.rb'",}
总结

以上是内存溢出为你收集整理的linux-puppet onlyif with pgrep不起作用全部内容,希望文章能够帮你解决linux-puppet onlyif with pgrep不起作用所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/yw/1035257.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-24
下一篇 2022-05-24

发表评论

登录后才能评论

评论列表(0条)

保存