]> git.openstreetmap.org Git - chef.git/blob - cookbooks/apache/definitions/apache_site.rb
Fix typo
[chef.git] / cookbooks / apache / definitions / apache_site.rb
1 #
2 # Cookbook Name:: apache
3 # Definition:: apache_site
4 #
5 # Copyright 2010, 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 define :apache_site, :action => [ :create, :enable ], :variables => {} do
21   name = params[:name]
22   directory = params[:directory] || "/var/www/#{name}"
23   site_action = params[:action]
24   link_name = name == "default" ? "000-default" : name
25
26   if site_action.include?(:create) or site_action.include?(:enable)
27     template "/etc/apache2/sites-available/#{name}" do
28       cookbook params[:cookbook]
29       source params[:template]
30       owner "root"
31       group "root"
32       mode 0644
33       variables params[:variables].merge(:name => name, :directory => directory)
34       if File.exists?("/etc/apache2/sites-enabled/#{link_name}")
35         notifies :reload, resources(:service => "apache2")
36       end
37     end
38   end
39
40   if site_action.include?(:enable)
41     execute "a2ensite-#{name}" do
42       command "/usr/sbin/a2ensite #{name}"
43       notifies :restart, resources(:service => "apache2")
44       not_if { File.exists?("/etc/apache2/sites-enabled/#{link_name}") }
45     end
46   elsif site_action.include?(:disable) or site_action.include?(:delete)
47     execute "a2dissite-#{name}" do
48       action :run
49       command "/usr/sbin/a2dissite #{name}"
50       notifies :restart, resources(:service => "apache2")
51       only_if { File.exists?("/etc/apache2/sites-enabled/#{link_name}") }
52     end
53   end
54
55   if site_action.include?(:delete)
56     file "/etc/apache2/sites-available/#{name}" do
57       action :delete
58     end
59   end
60 end