Notifying one resource from a provider


#1

For one of my projects, I need to be able to tell the deploy resource how
to restart a service.

Currently, I do it like this:

unless new_resource.restart_command
new_resource.restart_command do
run_context.resource_collection.find(:service =>
“tomcat6”).run_action(:restart)
end
end

the trouble with this approach is that tomcat6 gets restarted immediately
when deploy triggers a restart. Instead, I want deploy to “notify” tomcat6
to restart at the end of the chef run.
what function can be called to add something to the notification stack?
I’m thinking something like this, but no idea if it would work?

unless new_resource.restart_command
new_resource.restart_command do

run_context.notifies_delayed(Chef::Resource::Notification.new(:service =>
“tomcat6”, :restart, self))
end
end

Thanks!


#2

Should’ve just tried it… it worked!

put this into the provider definition, and can arbitrarily trigger a
notification

run_context.notifies_delayed(Chef::Resource::Notification.new(“service[tomcat6]”,
:restart, self))

On Tue, Nov 12, 2013 at 3:22 PM, Jesse Campbell hikeit@gmail.com wrote:

For one of my projects, I need to be able to tell the deploy resource how
to restart a service.

Currently, I do it like this:

unless new_resource.restart_command
new_resource.restart_command do
run_context.resource_collection.find(:service =>
“tomcat6”).run_action(:restart)
end
end

the trouble with this approach is that tomcat6 gets restarted immediately
when deploy triggers a restart. Instead, I want deploy to “notify” tomcat6
to restart at the end of the chef run.
what function can be called to add something to the notification stack?
I’m thinking something like this, but no idea if it would work?

unless new_resource.restart_command
new_resource.restart_command do

run_context.notifies_delayed(Chef::Resource::Notification.new(:service =>
“tomcat6”, :restart, self))
end
end

Thanks!