2 # Cookbook Name:: apache
 
   3 # Definition:: apache_site
 
   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_site, :action => [ :create, :enable ], :variables => {} do
 
  22   directory = params[:directory] || "/var/www/#{name}"
 
  23   site_action = params[:action]
 
  24   link_name = name == "default" ? "000-default" : name
 
  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]
 
  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")
 
  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}") }
 
  46   elsif site_action.include?(:disable) or site_action.include?(:delete)
 
  47     execute "a2dissite-#{name}" do
 
  49       command "/usr/sbin/a2dissite #{name}"
 
  50       notifies :restart, resources(:service => "apache2")
 
  51       only_if { File.exists?("/etc/apache2/sites-enabled/#{link_name}") }
 
  55   if site_action.include?(:delete)
 
  56     file "/etc/apache2/sites-available/#{name}" do