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