]> git.openstreetmap.org Git - chef.git/blob - cookbooks/apache/providers/site.rb
We want ::File here not Chef::Provider::File
[chef.git] / cookbooks / apache / providers / site.rb
1 #
2 # Cookbook Name:: postgresql
3 # Provider:: postgresql_database
4 #
5 # Copyright 2012, 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 => new_resource.directory)
32     if enabled?
33       notifies :reload, "service[apache2]"
34     end
35   end
36
37   new_resource.updated_by_last_action(t.updated_by_last_action?)
38 end
39
40 action :enable do
41   l = link enabled_file do
42     to available_file
43     owner "root"
44     group "root"
45     notifies :reload, "service[apache2]"
46   end
47
48   new_resource.updated_by_last_action(l.updated_by_last_action?)
49 end
50
51 action :disable do
52   l = link enabled_file do
53     action :delete
54     notifies :reload, "service[apache2]"
55   end
56
57   new_resource.updated_by_last_action(l.updated_by_last_action?)
58 end
59
60 action :delete do
61   f = file available_name do
62     action :delete
63   end
64
65   new_resource.updated_by_last_action(f.updated_by_last_action?)
66 end
67
68 def available_name
69   "/etc/apache2/sites-available/#{new_resource.name}"
70 end
71
72 def enabled_name
73   case new_resource.name
74   when "default"
75     "/etc/apache2/sites-enabled/000-default"
76   else
77     "/etc/apache2/sites-enabled/#{new_resource.name}"
78   end
79 end
80
81 def enabled?
82   ::File.exists?(enabled_name)
83 end