]> git.openstreetmap.org Git - chef.git/blob - cookbooks/apache/providers/conf.rb
beef75ea55952b42c9e2cfdbcf86469e69177254
[chef.git] / cookbooks / apache / providers / conf.rb
1 #
2 # Cookbook Name:: apache
3 # Provider:: 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 #     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 def whyrun_supported?
21   true
22 end
23
24 action :create do
25   if node[:lsb][:release].to_f >= 14.04
26     create_conf
27   end
28 end
29
30 action :enable do
31   if node[:lsb][:release].to_f >= 14.04
32     enable_conf
33   else
34     create_conf
35   end
36 end
37
38 action :disable do
39   if node[:lsb][:release].to_f >= 14.04
40     disable_conf
41   else
42     delete_conf
43   end
44 end
45
46 action :delete do
47   if node[:lsb][:release].to_f >= 14.04
48     delete_conf
49   end
50 end
51
52 def create_conf
53   t = template available_name do
54     cookbook new_resource.cookbook
55     source new_resource.template
56     owner "root"
57     group "root"
58     mode 0644
59     variables new_resource.variables
60     notifies :reload, "service[apache2]" if enabled? or available_name == enabled_name
61   end
62
63   new_resource.updated_by_last_action(t.updated_by_last_action?)
64 end
65
66 def enable_conf
67   l = link enabled_name do
68     to available_name
69     owner "root"
70     group "root"
71     notifies :reload, "service[apache2]"
72   end
73
74   new_resource.updated_by_last_action(l.updated_by_last_action?)
75 end
76
77 def disable_conf
78   l = link enabled_name do
79     action :delete
80     notifies :reload, "service[apache2]"
81   end
82
83   new_resource.updated_by_last_action(l.updated_by_last_action?)
84 end
85
86 def delete_conf
87   f = file available_name do
88     action :delete
89   end
90
91   new_resource.updated_by_last_action(f.updated_by_last_action?)
92 end
93
94 def available_name
95   if node[:lsb][:release].to_f >= 14.04
96     "/etc/apache2/conf-available/#{new_resource.name}"
97   else
98     "/etc/apache2/conf.d/#{new_resource.name}"
99   end
100 end
101
102 def enabled_name
103   if node[:lsb][:release].to_f >= 14.04
104     "/etc/apache2/conf-enabled/#{new_resource.name}"
105   else
106     "/etc/apache2/conf.d/#{new_resource.name}"
107   end
108 end
109
110 def enabled?
111   ::File.exists?(enabled_name)
112 end