问题
I am wondering if there is a way to cancel a notification to restart a service that was set to delayed. For example, here is a configuration change code block:
template "/etc/myapp/myconfig.conf" do
source "myconfig.conf.erb"
mode 0600
notifies :restart, "service[myapp]", :delayed
end
But then at the end of my recipe, I have some logic that will actually disable the app if certain conditions are met. This works fine, but then just after the disable (at the end of the chef run), the delayed restart request kicks in and restarts the process. I'm wondering if there is a way to tell chef to cancel all restart requests for the service if it get's disabled. Thoughts?
回答1:
It can be done, but it is not pretty. You would need to reach into the [run_context
][1] and get a hold of the [delayed_notification_collection
][2]. You could then remove the notification. But be aware, this is mucking pretty deeply into the internals of chef, which is highly discouraged.
take a look at this "cookbook" for an example. It's only been tested to the extent that the test-kitchen tests exercise it.
来源:https://stackoverflow.com/questions/26655604/chef-client-cancel-notifies-delayed