]> git.openstreetmap.org Git - chef.git/blobdiff - cookbooks/munin/resources/plugin_conf.rb
Modernise more LWRPs
[chef.git] / cookbooks / munin / resources / plugin_conf.rb
index 88b453d9a695c269f78057a1a61a797ce9abd292..c23efa234d0b92ce24260a2a431c5702a827fb4e 100644 (file)
 # limitations under the License.
 #
 
-actions :create, :delete
 default_action :create
 
-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 => {}
+property :plugin_conf, :kind_of => String, :name_attribute => true
+property :cookbook, :kind_of => [String, nil]
+property :template_source, :kind_of => String, :required => true
+property :variables, :kind_of => Hash, :default => {}
+property :restart_munin, :kind_of => [TrueClass, FalseClass], :default => true
+
+action :create do
+  template config_file do
+    cookbook new_resource.cookbook
+    source new_resource.template_source
+    owner "root"
+    group "root"
+    mode 0o644
+    variables new_resource.variables.merge(:name => new_resource.plugin_conf)
+  end
+end
+
+action :delete do
+  file config_file do
+    action :delete
+  end
+end
+
+action_class do
+  def config_file
+    "/etc/munin/plugin-conf.d/#{new_resource.plugin_conf}"
+  end
+end
+
+def after_created
+  notifies :restart, "service[munin-node]" if restart_munin
+end