2 # Cookbook Name:: tilecache
5 # Copyright 2011, 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.
22 certificate = node[:tilecache][:ssl][:certificate]
23 node.default[:ssl][:certificates] = node[:ssl][:certificates] | [certificate]
26 include_recipe "squid"
27 include_recipe "nginx"
36 # oathtool for QoS token
39 tilecaches = search(:node, "roles:tilecache").sort_by { |n| n[:hostname] }
40 tilerenders = search(:node, "roles:tile").sort_by { |n| n[:hostname] }
42 tilecache_tokens = data_bag_item("tilecache", "tokens")
44 tilecaches.each do |cache|
45 cache.ipaddresses(:family => :inet, :role => :external).sort.each do |address|
46 firewall_rule "accept-squid" do
49 source "net:#{address}"
55 firewall_rule "accept-squid-icp" do
58 source "net:#{address}"
64 firewall_rule "accept-squid-icp-reply" do
76 squid_fragment "tilecache" do
77 template "squid.conf.erb"
78 variables :caches => tilecaches, :renders => tilerenders
81 template "/etc/logrotate.d/squid" do
82 source "logrotate.squid.erb"
88 nginx_site "default" do
92 resolvers = node[:networking][:nameservers].map do |resolver|
93 IPAddr.new(resolver).ipv6? ? "[#{resolver}]" : resolver
96 nginx_site "tile-ssl" do
97 template "nginx_tile_ssl.conf.erb"
98 variables :certificate => certificate, :resolvers => resolvers, :caches => tilecaches
101 template "/usr/local/bin/nginx_generate_tilecache_qos_map" do
102 source "nginx_generate_tilecache_qos_map.erb"
106 variables :tokens => tilecache_tokens
109 template "/etc/cron.d/tilecache" do
116 execute "execute_nginx_generate_tilecache_qos_map" do
117 command "/usr/local/bin/nginx_generate_tilecache_qos_map"
118 creates "/etc/nginx/conf.d/tile_qos_rates.map"
122 service "nginx-certificate-restart" do
125 subscribes :restart, "cookbook_file[/etc/ssl/certs/rapidssl.pem]"
126 subscribes :restart, "file[/etc/ssl/certs/#{certificate}.pem]"
127 subscribes :restart, "file[/etc/ssl/private/#{certificate}.key]"
130 template "/etc/logrotate.d/nginx" do
131 source "logrotate.nginx.erb"
137 tilerenders.each do |render|
138 munin_plugin "ping_#{render[:fqdn]}" do
140 conf "munin.ping.erb"
141 conf_variables :host => render[:fqdn]