]> git.openstreetmap.org Git - chef.git/blob - cookbooks/apache/providers/module.rb
e824a03433e5d0e986d5be4fc82b3119165b31d9
[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 0644
37       variables new_resource.variables
38     end
39   end
40 end
41
42 action :enable do
43   link enabled_name("load") do
44     to available_name("load")
45     owner "root"
46     group "root"
47   end
48
49   link enabled_name("conf") do
50     to available_name("conf")
51     owner "root"
52     group "root"
53     only_if { ::File.exist?(available_name("conf")) }
54   end
55 end
56
57 action :disable do
58   link enabled_name("load") do
59     action :delete
60   end
61
62   link enabled_name("conf") do
63     action :delete
64   end
65 end
66
67 action :delete do
68   package package_name do
69     action :remove
70   end
71 end
72
73 def package_name
74   new_resource.package || "libapache2-mod-#{new_resource.name}"
75 end
76
77 def available_name(extension)
78   "/etc/apache2/mods-available/#{new_resource.name}.#{extension}"
79 end
80
81 def enabled_name(extension)
82   "/etc/apache2/mods-enabled/#{new_resource.name}.#{extension}"
83 end
84
85 def installed?
86   ::File.exist?(available_name("load"))
87 end