]> git.openstreetmap.org Git - chef.git/blob - cookbooks/munin/definitions/munin_plugin.rb
Improve idempotency of apache_module
[chef.git] / cookbooks / munin / definitions / munin_plugin.rb
1 #
2 # Cookbook Name:: munin
3 # Definition:: munin_plugin
4 #
5 # Copyright 2010, OpenStreetMap Foundation
6 #
7 # Licensed under the Apache License, Version 2.0 (the "License");
8 # you may not use this file except in compliance with the License.
9 # You may obtain a copy of the License at
10 #
11 #     http://www.apache.org/licenses/LICENSE-2.0
12 #
13 # Unless required by applicable law or agreed to in writing, software
14 # distributed under the License is distributed on an "AS IS" BASIS,
15 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 # See the License for the specific language governing permissions and
17 # limitations under the License.
18 #
19
20 define :munin_plugin, :action => :create do
21   target = params[:target] || params[:name]
22
23   if File.exists?(target)
24     target_path = target
25   elsif File.exists?("/usr/local/share/munin/plugins/#{target}")
26     target_path = "/usr/local/share/munin/plugins/#{target}"
27   elsif File.exists?("/usr/share/munin/plugins/#{target}")
28     target_path = "/usr/share/munin/plugins/#{target}"
29   else
30     target_path = nil
31   end
32
33   if target_path.nil? or params[:action] == :delete
34     link "/etc/munin/plugins/#{params[:name]}" do
35       action :delete
36     end
37   else
38     link "/etc/munin/plugins/#{params[:name]}" do
39       action params[:action]
40       to target_path
41       notifies :restart, "service[munin-node]"
42     end
43   end
44
45   if params[:conf]
46     conf_template = params[:conf]
47     conf_cookbook = params[:conf_cookbook]
48     conf_variables = params[:conf_variables]
49
50     munin_plugin_conf params[:name] do
51       action params[:action]
52       template conf_template
53       if conf_cookbook
54         cookbook conf_cookbook
55       end
56       if conf_variables
57         variables conf_variables
58       end
59     end
60   end
61 end