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