Created
June 4, 2012 04:38
-
-
Save adamhjk/2866378 to your computer and use it in GitHub Desktop.
Re-factored Apache cookbook
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# | |
# Cookbook Name:: apache | |
# Recipe:: default | |
# | |
# Copyright 2012, YOUR_COMPANY_NAME | |
# | |
# All rights reserved - Do Not Redistribute | |
# | |
package "apache2" do | |
action :install | |
end | |
service "apache2" do | |
action [ :start, :enable ] | |
end | |
execute "a2dissite default" do | |
only_if do | |
File.symlink?("/etc/apache2/sites-enabled/000-default") | |
end | |
notifies :restart, "service[apache2]" | |
end | |
node['apache']['sites'].each do |site_name, site_data| | |
document_root = "/srv/apache/#{site_name}" | |
template "/etc/apache2/sites-available/#{site_name}" do | |
source "custom.erb" | |
mode "0644" | |
variables( | |
:document_root => document_root, | |
:port => site_data['port'] | |
) | |
notifies :restart, "service[apache2]" | |
end | |
execute "a2ensite #{site_name}" do | |
not_if do | |
File.symlink?("/etc/apache2/sites-enabled/#{site_name}") | |
end | |
notifies :restart, "service[apache2]" | |
end | |
directory document_root do | |
mode "0755" | |
recursive true | |
end | |
template "#{document_root}/index.html" do | |
source "index.html.erb" | |
variables( | |
:site_name => site_name, | |
:port => site_data['port'] | |
) | |
mode "0644" | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
The references to File.symlink need to point to "#{site_name}.conf" in newer versions of ubuntu (see http://www.kublermdk.com/2013/11/13/apache-vhosts-broken-after-ubuntu-13-10-upgrade/)