]> git.openstreetmap.org Git - chef.git/blob - cookbooks/apache/providers/conf.rb
Use inline compile mode for apache LWRPs
[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 use_inline_resources
25
26 action :create do # ~FC017
27   if node[:lsb][:release].to_f >= 14.04
28     create_conf
29   end
30 end
31
32 action :enable do # ~FC017
33   if node[:lsb][:release].to_f >= 14.04
34     enable_conf
35   else
36     create_conf
37   end
38 end
39
40 action :disable do # ~FC017
41   if node[:lsb][:release].to_f >= 14.04
42     disable_conf
43   else
44     delete_conf
45   end
46 end
47
48 action :delete do # ~FC017
49   if node[:lsb][:release].to_f >= 14.04
50     delete_conf
51   end
52 end
53
54 def create_conf
55   template available_name do
56     cookbook new_resource.cookbook
57     source new_resource.template
58     owner "root"
59     group "root"
60     mode 0644
61     variables new_resource.variables
62   end
63 end
64
65 def enable_conf
66   link enabled_name do
67     to available_name
68     owner "root"
69     group "root"
70   end
71 end
72
73 def disable_conf
74   link enabled_name do
75     action :delete
76   end
77 end
78
79 def delete_conf
80   file available_name do
81     action :delete
82   end
83 end
84
85 def available_name
86   if node[:lsb][:release].to_f >= 14.04
87     "/etc/apache2/conf-available/#{new_resource.name}.conf"
88   else
89     "/etc/apache2/conf.d/#{new_resource.name}"
90   end
91 end
92
93 def enabled_name
94   if node[:lsb][:release].to_f >= 14.04
95     "/etc/apache2/conf-enabled/#{new_resource.name}.conf"
96   else
97     "/etc/apache2/conf.d/#{new_resource.name}"
98   end
99 end