If statement 在chef中使用if语句的正确方法是什么?

If statement 在chef中使用if语句的正确方法是什么?,if-statement,chef-infra,If Statement,Chef Infra,在这里,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 正如你在上一个问题中指出的,你所拥有的与厨师代码无关。请从教程开始学习编写厨师配方代码的基础知识 这里有

在这里,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

正如你在上一个问题中指出的,你所拥有的与厨师代码无关。请从教程开始学习编写厨师配方代码的基础知识

这里有一种方法可以检查给定的进程是否正在与chef一起运行。您需要用进程名替换procname。然而,这是Linux的一个例子,如果您需要Windows,则只需将“if”语句更改为类似于sc query的“find RUNNING”


请在阅读厨师指南的同时,花一些时间阅读和阅读。在StackOverflow上,一次又一次地问同样的问题是不受欢迎的。
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