I’m separating the recipe(s) that create a service from the recipes that manage relevant configuration files. When such configuration files change, if there’s also the service, I’d like to restart it.
How can I notify a service only if is already defined?
The only thing I’ve found is this:
resource_exists = proc do |name| begin resources name true rescue Chef::Exceptions::ResourceNotFound false end end # Use: template '/etc/my/template.conf' do source 'template.conf.erb' mode '640' notifies :run, 'ruby_block[my-resource-supposed-to-exist]' if resource_exists['ruby_block[my-resource-supposed-to-exist]'] end
Is there a more “Chef” way to accomplish this?