]> git.openstreetmap.org Git - chef.git/blob - cookbooks/apache/resources/conf.rb
Merge remote-tracking branch 'tigerfell/pr257'
[chef.git] / cookbooks / apache / resources / conf.rb
1 #
2 # Cookbook:: apache
3 # Resource:: apache_conf
4 #
5 # Copyright:: 2014, 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 # https://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 unified_mode true
21
22 default_action [:create, :enable]
23
24 property :conf, :kind_of => String, :name_property => true
25 property :cookbook, :kind_of => String
26 property :template, :kind_of => String, :required => [:create]
27 property :variables, :kind_of => Hash, :default => {}
28 property :reload_apache, :kind_of => [TrueClass, FalseClass], :default => true
29
30 action :create do
31   create_conf
32 end
33
34 action :enable do
35   enable_conf
36 end
37
38 action :disable do
39   disable_conf
40 end
41
42 action :delete do
43   delete_conf
44 end
45
46 action_class do
47   def create_conf
48     declare_resource :template, available_name do
49       cookbook new_resource.cookbook
50       source new_resource.template
51       owner "root"
52       group "root"
53       mode "644"
54       variables new_resource.variables
55     end
56   end
57
58   def enable_conf
59     link enabled_name do
60       to available_name
61       owner "root"
62       group "root"
63     end
64   end
65
66   def disable_conf
67     link enabled_name do
68       action :delete
69     end
70   end
71
72   def delete_conf
73     file available_name do
74       action :delete
75     end
76   end
77
78   def available_name
79     "/etc/apache2/conf-available/#{new_resource.conf}.conf"
80   end
81
82   def enabled_name
83     "/etc/apache2/conf-enabled/#{new_resource.conf}.conf"
84   end
85 end
86
87 def after_created
88   notifies :reload, "service[apache2]" if reload_apache
89 end