]> git.openstreetmap.org Git - chef.git/commitdiff
Use inline compile mode for munin LWRPs
authorTom Hughes <tom@compton.nu>
Tue, 10 Feb 2015 00:20:46 +0000 (00:20 +0000)
committerTom Hughes <tom@compton.nu>
Tue, 10 Feb 2015 00:47:24 +0000 (00:47 +0000)
cookbooks/munin/providers/plugin.rb
cookbooks/munin/providers/plugin_conf.rb
cookbooks/munin/resources/plugin.rb
cookbooks/munin/resources/plugin_conf.rb

index 2937190665a63025bbebe5ce350e34df90f6048d..e469acb6d1610a70e4d8c7d3a74f9189c666b1fa 100644 (file)
@@ -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
index 7a87c88003e1bae204284b4a6310b9ebcb610afc..4263165cdaa7e5adc4f78c2eac39469ce5e2d3fa 100644 (file)
@@ -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
index 758d9b413da8762cceb945e2cc6793924d61aad0..5d36e13a5ac94b14d2c2cc86e3517789b8cd7d1b 100644 (file)
@@ -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
index 88b453d9a695c269f78057a1a61a797ce9abd292..e4b99965db78ee7d8e7c8399e8b40dacee2b960b 100644 (file)
@@ -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