]> git.openstreetmap.org Git - chef.git/blob - cookbooks/apache/providers/module.rb
252b5e8165f2377757cc40eb71e5a0b4b686a89c
[chef.git] / cookbooks / apache / providers / module.rb
1 #
2 # Cookbook Name:: apache
3 # Provider:: apache_module
4 #
5 # Copyright 2013, 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 :install do
27   unless installed?
28     package package_name
29   end
30
31   if new_resource.conf # ~FC023
32     template available_name("conf") do
33       source new_resource.conf
34       owner "root"
35       group "root"
36       mode 0o644
37       variables new_resource.variables
38     end
39   end
40 end
41
42 action :enable do
43   execute "a2enmod-#{new_resource.name}" do
44     command "a2enmod #{new_resource.name}"
45     user "root"
46     group "root"
47     not_if { ::File.exist?(enabled_name("load")) }
48   end
49
50   link enabled_name("load") do
51     to available_name("load")
52     owner "root"
53     group "root"
54   end
55
56   link enabled_name("conf") do
57     to available_name("conf")
58     owner "root"
59     group "root"
60     only_if { ::File.exist?(available_name("conf")) }
61   end
62 end
63
64 action :disable do
65   link enabled_name("load") do
66     action :delete
67   end
68
69   link enabled_name("conf") do
70     action :delete
71   end
72 end
73
74 action :delete do
75   package package_name do
76     action :remove
77   end
78 end
79
80 def package_name
81   new_resource.package || "libapache2-mod-#{new_resource.name}"
82 end
83
84 def available_name(extension)
85   "/etc/apache2/mods-available/#{new_resource.name}.#{extension}"
86 end
87
88 def enabled_name(extension)
89   "/etc/apache2/mods-enabled/#{new_resource.name}.#{extension}"
90 end
91
92 def installed?
93   ::File.exist?(available_name("load"))
94 end