]> git.openstreetmap.org Git - chef.git/blob - cookbooks/apache/definitions/apache_module.rb
Allow the listen host address to be set for apache
[chef.git] / cookbooks / apache / definitions / apache_module.rb
1 #
2 # Cookbook Name:: apache
3 # Definition:: apache_module
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_module, :action => [ :install, :enable ], :variables => {} do
21   name = params[:name]
22   module_action = params[:action]
23
24   if params[:package].nil? or params[:package].empty?
25     package_name = "libapache2-mod-#{name}"
26   else
27     package_name = params[:package]
28   end
29
30   if module_action.include?(:install)
31     package package_name do
32       action :install
33       not_if { File.exists?("/etc/apache2/mods-available/#{name}.load") }
34     end
35
36     if params[:conf]
37       template "/etc/apache2/mods-available/#{name}.conf" do
38         source params[:conf]
39         owner "root"
40         group "root"
41         mode 0644
42         variables params[:variables]
43         if File.exists?("/etc/apache2/mods-enabled/#{name}.load")
44           notifies :reload, resources(:service => "apache2")
45         end
46       end
47     end
48   end
49
50   if module_action.include?(:enable)
51     execute "a2enmod-#{name}" do
52       command "/usr/sbin/a2enmod #{name}"
53       notifies :restart, resources(:service => "apache2")
54       not_if { File.exists?("/etc/apache2/mods-enabled/#{name}.load") }
55     end
56   elsif module_action.include?(:disable) or module_action.include?(:remove)
57     execute "a2dismod-#{name}" do
58       command "/usr/sbin/a2dismod #{name}"
59       notifies :restart, resources(:service => "apache2")
60       only_if { File.exists?("/etc/apache2/mods-enabled/#{name}.load") }
61     end
62   end
63
64   if module_action.include?(:remove)
65     package package_name do
66       action :remove
67       only_if { File.exists?("/etc/apache2/mods-available/#{name}.load") }
68     end
69   end
70 end