【问题标题】:what is the right way to use if statement in chef?在厨师中使用if语句的正确方法是什么?
【发布时间】:2017-03-02 05:39:27
【问题描述】:
这里的else部分不起作用我无法弄清楚为什么,如何成功执行此代码?
service 'McAfeeFramework' do
if{ supports :status =>true}
File.write('c:\chef-repo\n1.txt','running')
else
File.write('c:\chef-repo\n1.txt','not running')
end
【问题讨论】:
标签:
if-statement
chef-infra
【解决方案2】:
这是一种检查给定进程是否与厨师一起运行的方法。您需要将 procname 替换为您的进程名称。但是,这是 Linux 的示例,如果您需要 Windows,则需要将 only_if 语句更改为 sc query | find "RUNNING
file 'running process' do
path '/tmp/running_process'
content 'services is running'
only_if 'pgrep procname && echo 0'
action :create
end
file 'stoped process' do
path '/tmp/stoped_process'
content 'services is not running'
only_if 'pgrep procname || echo 1'
action :create
end