2 # Cookbook Name:: apache
3 # Definition:: apache_module
5 # Copyright 2010, OpenStreetMap Foundation
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
11 # http://www.apache.org/licenses/LICENSE-2.0
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.
20 define :apache_module, :action => [ :install, :enable ], :variables => {} do
22 module_action = params[:action]
24 if params[:package].nil? or params[:package].empty?
25 package_name = "libapache2-mod-#{name}"
27 package_name = params[:package]
30 if module_action.include?(:install)
31 package package_name do
33 not_if { File.exists?("/etc/apache2/mods-available/#{name}.load") }
37 template "/etc/apache2/mods-available/#{name}.conf" do
42 variables params[:variables]
43 if File.exists?("/etc/apache2/mods-enabled/#{name}.load")
44 notifies :reload, "service[apache2]"
50 if module_action.include?(:enable)
51 execute "a2enmod-#{name}" do
52 command "/usr/sbin/a2enmod #{name}"
53 notifies :restart, "service[apache2]"
54 not_if { File.exists?("/etc/apache2/mods-enabled/#{name}.load") }
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, "service[apache2]"
60 only_if { File.exists?("/etc/apache2/mods-enabled/#{name}.load") }
64 if module_action.include?(:remove)
65 package package_name do
67 only_if { File.exists?("/etc/apache2/mods-available/#{name}.load") }