]> git.openstreetmap.org Git - chef.git/blob - cookbooks/apache/providers/site.rb
Revert "Enable HSTS for all apache served SSL sites"
[chef.git] / cookbooks / apache / providers / site.rb
1 #
2 # Cookbook Name:: apache
3 # Provider:: apache_site
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 :create do
25   t = template available_name do
26     cookbook new_resource.cookbook
27     source new_resource.template
28     owner "root"
29     group "root"
30     mode 0644
31     variables new_resource.variables.merge(:name => new_resource.name, :directory => site_directory)
32     notifies :reload, "service[apache2]" if enabled?
33   end
34
35   new_resource.updated_by_last_action(t.updated_by_last_action?)
36 end
37
38 action :enable do
39   l = link enabled_name do
40     to available_name
41     owner "root"
42     group "root"
43     notifies :reload, "service[apache2]"
44   end
45
46   new_resource.updated_by_last_action(l.updated_by_last_action?)
47 end
48
49 action :disable do
50   l = link enabled_name do
51     action :delete
52     notifies :reload, "service[apache2]"
53   end
54
55   new_resource.updated_by_last_action(l.updated_by_last_action?)
56 end
57
58 action :delete do
59   f = file available_name do
60     action :delete
61   end
62
63   new_resource.updated_by_last_action(f.updated_by_last_action?)
64 end
65
66 def site_directory
67   new_resource.directory || "/var/www/#{new_resource.name}"
68 end
69
70 def available_name
71   if node[:lsb][:release].to_f >= 14.04
72     "/etc/apache2/sites-available/#{new_resource.name}.conf"
73   else
74     "/etc/apache2/sites-available/#{new_resource.name}"
75   end
76 end
77
78 def enabled_name
79   if node[:lsb][:release].to_f >= 14.04
80     case new_resource.name
81     when "default"
82       "/etc/apache2/sites-enabled/000-default.conf"
83     else
84       "/etc/apache2/sites-enabled/#{new_resource.name}.conf"
85     end
86   else
87     case new_resource.name
88     when "default"
89       "/etc/apache2/sites-enabled/000-default"
90     else
91       "/etc/apache2/sites-enabled/#{new_resource.name}"
92     end
93   end
94 end
95
96 def enabled?
97   ::File.exists?(enabled_name)
98 end