]> git.openstreetmap.org Git - chef.git/blob - cookbooks/tilecache/recipes/default.rb
ce4819ad098a21621f162de63ef6a76707adb55c
[chef.git] / cookbooks / tilecache / recipes / default.rb
1 #
2 # Cookbook Name:: tilecache
3 # Recipe:: default
4 #
5 # Copyright 2011, 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 require "ipaddr"
21
22 certificate = node[:tilecache][:ssl][:certificate]
23 node.default[:ssl][:certificates] = node[:ssl][:certificates] | [certificate]
24
25 include_recipe "ssl"
26 include_recipe "squid"
27 include_recipe "nginx"
28
29 package "apache2" do
30   action :remove
31 end
32
33 package "xz-utils"
34
35 tilecaches = search(:node, "roles:tilecache").sort_by { |n| n[:hostname] }
36 tilerenders = search(:node, "roles:tile").sort_by { |n| n[:hostname] }
37
38 tilecaches.each do |cache|
39   cache.ipaddresses(:family => :inet, :role => :external).sort.each do |address|
40     firewall_rule "accept-squid" do
41       action :accept
42       family "inet"
43       source "net:#{address}"
44       dest "fw"
45       proto "tcp:syn"
46       dest_ports "3128"
47       source_ports "1024:"
48     end
49     firewall_rule "accept-squid-icp" do
50       action :accept
51       family "inet"
52       source "net:#{address}"
53       dest "fw"
54       proto "udp"
55       dest_ports "3130"
56       source_ports "3130"
57     end
58     firewall_rule "accept-squid-icp-reply" do
59       action :accept
60       family "inet"
61       source "fw"
62       dest "net:#{address}"
63       proto "udp"
64       dest_ports "3130"
65       source_ports "3130"
66     end
67   end
68 end
69
70 squid_fragment "tilecache" do
71   template "squid.conf.erb"
72   variables :caches => tilecaches, :renders => tilerenders
73 end
74
75 template "/etc/logrotate.d/squid" do
76   source "logrotate.squid.erb"
77   owner "root"
78   group "root"
79   mode 0644
80 end
81
82 nginx_site "default" do
83   action [:delete]
84 end
85
86 resolvers = node[:networking][:nameservers].map do |resolver|
87   IPAddr.new(resolver).ipv6? ? "[#{resolver}]" : "#{resolver}"
88 end
89
90 nginx_site "tile-ssl" do
91   template "nginx_tile_ssl.conf.erb"
92   variables :certificate => certificate, :resolvers => resolvers
93 end
94
95 service "nginx-certificate-restart" do
96   service_name "nginx"
97   action :nothing
98   subscribes :restart, "cookbook_file[/etc/ssl/certs/rapidssl.pem]"
99   subscribes :restart, "cookbook_file[/etc/ssl/certs/#{certificate}.pem]"
100   subscribes :restart, "file[/etc/ssl/private/#{certificate}.key]"
101 end
102
103 tilerenders.each do |render|
104   munin_plugin "ping_#{render[:fqdn]}" do
105     target "ping_"
106     conf "munin.ping.erb"
107     conf_variables :host => render[:fqdn]
108   end
109 end