Skip to content

Commit

Permalink
[COOK-620] ensure handler code is reloaded during daemonized chef runs
Browse files Browse the repository at this point in the history
  • Loading branch information
schisamo committed Jun 29, 2011
1 parent a1aded1 commit ad54151
Showing 1 changed file with 12 additions and 4 deletions.
16 changes: 12 additions & 4 deletions chef_handler/providers/default.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,17 @@
#

action :enable do
require @new_resource.source
klass = @new_resource.class_name.split('::').inject(Kernel) {|scope, const_name| scope.const_get(const_name)}
handler = klass.send(:new, *collect_args(@new_resource.arguments))
@new_resource.supports.each_key do |type|
klass = @new_resource.class_name.split('::').inject(Kernel) {|scope, const_name| scope.const_get(const_name)}
# use load instead of require to ensure the handler file
# is reloaded into memory each chef run. fixes COOK-620
Object.send(:remove_const, klass) rescue Chef::Log.debug("#{klass} has not been loaded")
GC.start
file_name = @new_resource.source
file_name << ".rb" unless file_name =~ /.*\.rb$/
load file_name
handler = klass.send(:new, *collect_args(@new_resource.arguments))
@new_resource.supports.each do |type, enable|
unless enable
# we have to re-enable the handler every chef run
# to ensure daemonized Chef always has the latest
# handler code. TODO: add a :reload action
Expand All @@ -31,6 +38,7 @@
Chef::Config.send("#{type.to_s}_handlers") << handler
new_resource.updated_by_last_action(true)
end
end
end

action :disable do
Expand Down

0 comments on commit ad54151

Please sign in to comment.