]> git.openstreetmap.org Git - chef.git/blob - cookbooks/apache/resources/conf.rb
Convert more URLs to https
[chef.git] / cookbooks / apache / resources / conf.rb
1 #
2 # Cookbook Name:: apache
3 # Resource:: apache_conf
4 #
5 # Copyright 2014, 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 # https://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 default_action [:create, :enable]
21
22 property :conf, :kind_of => String, :name_attribute => true
23 property :cookbook, :kind_of => String
24 property :template, :kind_of => String, :required => true
25 property :variables, :kind_of => Hash, :default => {}
26 property :reload_apache, :kind_of => [TrueClass, FalseClass], :default => true
27
28 action :create do
29   create_conf
30 end
31
32 action :enable do
33   enable_conf
34 end
35
36 action :disable do
37   disable_conf
38 end
39
40 action :delete do
41   delete_conf
42 end
43
44 action_class do
45   def create_conf
46     declare_resource :template, available_name do
47       cookbook new_resource.cookbook
48       source new_resource.template
49       owner "root"
50       group "root"
51       mode 0o644
52       variables new_resource.variables
53     end
54   end
55
56   def enable_conf
57     link enabled_name do
58       to available_name
59       owner "root"
60       group "root"
61     end
62   end
63
64   def disable_conf
65     link enabled_name do
66       action :delete
67     end
68   end
69
70   def delete_conf
71     file available_name do
72       action :delete
73     end
74   end
75
76   def available_name
77     "/etc/apache2/conf-available/#{new_resource.conf}.conf"
78   end
79
80   def enabled_name
81     "/etc/apache2/conf-enabled/#{new_resource.conf}.conf"
82   end
83 end
84
85 def after_created
86   notifies :reload, "service[apache2]" if reload_apache
87 end