From 9d27360314f8e4e9844cde4059f98fac52250d36 Mon Sep 17 00:00:00 2001 From: Tom Hughes Date: Tue, 10 Feb 2015 00:20:46 +0000 Subject: [PATCH] Use inline compile mode for munin LWRPs --- cookbooks/munin/providers/plugin.rb | 28 +++++++----------------- cookbooks/munin/providers/plugin_conf.rb | 11 ++++------ cookbooks/munin/resources/plugin.rb | 5 +++++ cookbooks/munin/resources/plugin_conf.rb | 9 ++++++++ 4 files changed, 26 insertions(+), 27 deletions(-) diff --git a/cookbooks/munin/providers/plugin.rb b/cookbooks/munin/providers/plugin.rb index 293719066..e469acb6d 100644 --- a/cookbooks/munin/providers/plugin.rb +++ b/cookbooks/munin/providers/plugin.rb @@ -21,50 +21,38 @@ def whyrun_supported? true end +use_inline_resources + action :create do link_action = case target_path when nil then :delete else :create end - l = link plugin_path do + link plugin_path do action link_action to target_path - notifies :restart, "service[munin-node]" end - updated = l.updated_by_last_action? - - if new_resource.conf - c = munin_plugin_conf new_resource.name do + if new_resource.conf # ~FC023 + munin_plugin_conf new_resource.name do cookbook new_resource.conf_cookbook template new_resource.conf variables new_resource.conf_variables end - - updated ||= c.updated_by_last_action? end - - new_resource.updated_by_last_action(updated) end action :delete do - l = link plugin_path do + link plugin_path do action :delete - notifies :restart, "service[munin-node]" end - updated = l.updated_by_last_action? - - if new_resource.conf - c = munin_plugin_conf new_resource.name do + if new_resource.conf # ~FC023 + munin_plugin_conf new_resource.name do action :delete end - - updated ||= c.updated_by_last_action? end - - new_resource.updated_by_last_action(updated) end def plugin_path diff --git a/cookbooks/munin/providers/plugin_conf.rb b/cookbooks/munin/providers/plugin_conf.rb index 7a87c8800..4263165cd 100644 --- a/cookbooks/munin/providers/plugin_conf.rb +++ b/cookbooks/munin/providers/plugin_conf.rb @@ -21,26 +21,23 @@ def whyrun_supported? true end +use_inline_resources + action :create do - t = template config_file do + template config_file do cookbook new_resource.cookbook source new_resource.template owner "root" group "root" mode 0644 variables new_resource.variables.merge(:name => new_resource.name) - notifies :restart, "service[munin-node]" end - - new_resource.updated_by_last_action(t.updated_by_last_action?) end action :delete do - f = file config_file do + file config_file do action :delete end - - new_resource.updated_by_last_action(f.updated_by_last_action?) end def config_file diff --git a/cookbooks/munin/resources/plugin.rb b/cookbooks/munin/resources/plugin.rb index 758d9b413..5d36e13a5 100644 --- a/cookbooks/munin/resources/plugin.rb +++ b/cookbooks/munin/resources/plugin.rb @@ -25,3 +25,8 @@ attribute :target, :kind_of => String attribute :conf, :kind_of => String attribute :conf_cookbook, :kind_of => String attribute :conf_variables, :kind_of => Hash, :default => {} + +def initialize(*args) + super + notifies :restart, "service[munin-node]" +end diff --git a/cookbooks/munin/resources/plugin_conf.rb b/cookbooks/munin/resources/plugin_conf.rb index 88b453d9a..e4b99965d 100644 --- a/cookbooks/munin/resources/plugin_conf.rb +++ b/cookbooks/munin/resources/plugin_conf.rb @@ -24,3 +24,12 @@ attribute :name, :kind_of => String, :name_attribute => true attribute :cookbook, :kind_of => String attribute :template, :kind_of => String, :required => true attribute :variables, :kind_of => Hash, :default => {} + +def initialize(*args) + super + begin + resources(:service => "munin-node").subscrbes(:restart, self) + rescue Chef::Exceptions::ResourceNotFound + # Ignore + end +end -- 2.43.2