2017-02-28 73 views
-2

這裏的其他部分沒有工作我無法找出原因,我如何成功地執行這個代碼?廚師如果使用陳述,正確的方法是什麼?

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 
+0

的可能的複製[是有可能使用支持聲明,如果聲明的廚師?](HTTP://計算器.COM /問題/ 42482182/IS-IT-可以使用的,支持語句式-if語句,在廚師) – Tensibai

+0

請在https://learn.chef.io讀廚師教程一起,花一些時間閱讀[旅遊]和[問]。一次又一次詢問同樣的事情在StackOverflow上不受歡迎。 – Tensibai

回答

0

正如您在上一個問題中指出的那樣,您在那裏的內容與字母代碼無關。請從https://learn.chef.io教程開始,瞭解編寫廚師食譜代碼的基礎知識。

0

這裏是檢查是否給定的過程與廚師運行的方式。您需要將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