2014-01-27 110 views
3

我很新Chef。我有一个配方,安装sendmail,它做我的配置。我注意到,Chef每次运行都会重新启动服务。这是因为我正在运行调用会话重新启动的execute厨师执行块

它看起来像这样:

execute "hashAccess" do 
    command "makemap hash /etc/mail/access < /etc/mail/access" 
    notifies :restart, "service[sendmail]" 
end 

我需要的,如果更新了access文件时才会调用它。

template "/etc/mail/access" do 
    source "access.erb" 
    mode "0644" 
    notifies :run, "execute[hashAccess]" 
end 

当文件更新时,execute被调用两次。 两种资源都在相同的配方,当我尝试definehashAccess我得到一个错误

ERROR: Cannot find a resource for define on amazon version 2013.09 

如何使执行资源仅调用时运行?

回答

6

您应该将action :nothing添加到您的执行资源中。

execute "hashAccess" do 
    command "makemap hash /etc/mail/access < /etc/mail/access" 
    action :nothing 
    notifies :restart, "service[sendmail]" 
end 

这样它不会被执行,除非被其他资源通知。

+0

谢谢!我知道它会很简单... :) –

+1

谢谢@Draco Ater – Robert