]> git.openstreetmap.org Git - chef.git/blob - cookbooks/apache/providers/module.rb
Convert apache_module to an LWRP
[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 action :install do
25   p = package package_name do
26     action :install
27     not_if { ::File.exists?(available_name("load")) }
28   end
29
30   updated = p.updated_by_last_action?
31
32   if new_resource.conf
33     t = template available_name("conf") do
34       source new_resource.conf
35       owner "root"
36       group "root"
37       mode 0644
38       variables new_resource.variables
39       notifies :reload, "service[apache2]" if enabled?
40     end
41
42     updated = updated || t.updated_by_last_action?
43   end
44
45   new_resource.updated_by_last_action(updated)
46 end
47
48 action :enable do
49   l = link enabled_name("load") do
50     to available_name("load")
51     owner "root"
52     group "root"
53     notifies :restart, "service[apache2]"
54   end
55
56   c = link enabled_name("conf") do
57     to available_name("conf")
58     owner "root"
59     group "root"
60     notifies :reload, "service[apache2]"
61     only_if { ::File.exists?(available_name("conf")) }
62   end
63
64   new_resource.updated_by_last_action(l.updated_by_last_action? || c.updated_by_last_action?)
65 end
66
67 action :disable do
68   l = link enabled_name("load") do
69     action :delete
70     notifies :restart, "service[apache2]"
71   end
72
73   c = link enabled_name("conf") do
74     action :delete
75     notifies :reload, "service[apache2]"
76   end
77
78   new_resource.updated_by_last_action(l.updated_by_last_action? || c.updated_by_last_action?)
79 end
80
81 action :delete do
82   p = package package_name do
83     action :remove
84   end
85
86   new_resource.updated_by_last_action(p.updated_by_last_action?)
87 end
88
89 def package_name
90   new_resource.package || "libapache2-mod-#{new_resource.name}"
91 end
92
93 def available_name(extension)
94   "/etc/apache2/mods-available/#{new_resource.name}.#{extension}"
95 end
96
97 def enabled_name(extension)
98   "/etc/apache2/mods-enabled/#{new_resource.name}.#{extension}"
99 end
100
101 def enabled?
102   ::File.exists?(enabled_name("load"))
103 end