|
3 | 3 | # Recipe:: default
|
4 | 4 | #
|
5 | 5 | # Copyright 2011, Fewbytes Technologies LTD
|
| 6 | +# Copyright 2012, Chris Roberts <[email protected]> |
6 | 7 | #
|
7 | 8 |
|
8 |
| -def compile_attr(prefix, v) |
9 |
| - case v |
10 |
| - when Array |
11 |
| - return "#{prefix}=#{v.join(" ")}" |
12 |
| - when String, Fixnum, Bignum, Float, Symbol |
13 |
| - "#{prefix}=#{v}" |
14 |
| - when Hash, Chef::Node::Attribute |
15 |
| - prefix += "." unless prefix.empty? |
16 |
| - return v.map {|key, value| compile_attr("#{prefix}#{key}", value)}.flatten |
17 |
| - else |
18 |
| - raise Chef::Exceptions::UnsupportedAction, "Sysctl cookbook can't handle values of type: #{v.class}" |
19 |
| - end |
20 |
| -end |
| 9 | +service "procps" |
21 | 10 |
|
22 |
| -if node.attribute?(:sysctl) |
| 11 | +sysctl_path = if(node[:sysctl][:conf_dir]) |
| 12 | + File.join(node[:sysctl][:conf_dir], '99-chef-attributes.conf') |
| 13 | + else |
| 14 | + node[:sysctl][:allow_sysctl_conf] ? '/etc/sysctl.conf' : nil |
| 15 | + end |
23 | 16 |
|
24 |
| - attr_txt = compile_attr("", node[:sysctl]).join("\n") + "\n" |
| 17 | +if(sysctl_path) |
| 18 | + template sysctl_path do |
| 19 | + action :nothing |
| 20 | + source 'sysctl.conf.erb' |
| 21 | + mode '0644' |
| 22 | + notifies :start, resources(:service => 'procps'), :immediately |
| 23 | + only_if do |
| 24 | + node[:sysctl][:attributes] && !node[:sysctl][:attributes].empty? |
| 25 | + end |
| 26 | + end |
25 | 27 |
|
26 |
| - file "/etc/sysctl.d/68-chef-attributes.conf" do |
27 |
| - content attr_txt |
28 |
| - mode "0644" |
29 |
| - notifies :start, "service[procps]", :immediately |
| 28 | + ruby_block 'sysctl config notifier' do |
| 29 | + block do |
| 30 | + true |
| 31 | + end |
| 32 | + notifies :create, resources(:template => sysctl_path), :delayed |
30 | 33 | end
|
31 | 34 | end
|
32 | 35 |
|
33 | 36 | cookbook_file "/etc/sysctl.d/69-chef-static.conf" do
|
34 | 37 | ignore_failure true
|
35 | 38 | mode "0644"
|
36 |
| - notifies :start, "service[procps]", :immediately |
| 39 | + notifies :start, "service[procps]" |
37 | 40 | end
|
38 | 41 |
|
39 | 42 | service "procps"
|
0 commit comments