]> git.openstreetmap.org Git - chef.git/blob - cookbooks/apache/resources/conf.rb
Use prometheus-exporters github releases instead of slow git clone
[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 property :restart_apache, :kind_of => [TrueClass, FalseClass], :default => false
30
31 action :create do
32   create_conf
33 end
34
35 action :enable do
36   enable_conf
37 end
38
39 action :disable do
40   disable_conf
41 end
42
43 action :delete do
44   delete_conf
45 end
46
47 action_class do
48   def create_conf
49     declare_resource :template, available_name do
50       cookbook new_resource.cookbook
51       source new_resource.template
52       owner "root"
53       group "root"
54       mode "644"
55       variables new_resource.variables
56     end
57   end
58
59   def enable_conf
60     link enabled_name do
61       to available_name
62       owner "root"
63       group "root"
64     end
65   end
66
67   def disable_conf
68     link enabled_name do
69       action :delete
70     end
71   end
72
73   def delete_conf
74     file available_name do
75       action :delete
76     end
77   end
78
79   def available_name
80     "/etc/apache2/conf-available/#{new_resource.conf}.conf"
81   end
82
83   def enabled_name
84     "/etc/apache2/conf-enabled/#{new_resource.conf}.conf"
85   end
86 end
87
88 def after_created
89   notifies :reload, "service[apache2]" if reload_apache
90   notifies :restart, "service[apache2]" if restart_apache
91 end