leeeennyy
leeeennyy

Reputation: 15

Only execute service once despite number of notifies in Chef

I currently have two files being created via templates in Chef. Both these templates currently notify a service when it is modified.

template '/etc/file1' do
    source 'file1.erb'
    owner 'root'
    group 'root'
    mode '644'
    notifies :restart, 'service[foo]'
end

template '/etc/file2' do
    source 'file2.erb'
    owner 'root'
    group 'root'
    mode '600'
    notifies :restart, 'service[foo]'
end

service "foo" do
    action :nothing
end

Is there a way where I can call the service only when either of these files are changed? The reason for this is because I want to avoid two instances of "foo" executing if both files were changed.

Upvotes: 0

Views: 161

Answers (1)

Szymon
Szymon

Reputation: 1525

In your example 'foo' service will be notified only once (and executed only once) and only if any of the files changes. Exactly as you expect.

Upvotes: 2

Related Questions