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 # https://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 include_recipe "fail2ban"
23 include_recipe "munin"
24 include_recipe "nginx"
25 include_recipe "squid"
38 # oathtool for QoS token
41 tilecaches = search(:node, "roles:tilecache").sort_by { |n| n[:hostname] }
42 tilerenders = search(:node, "roles:tile").sort_by { |n| n[:hostname] }
44 web_passwords = data_bag_item("web", "passwords")
46 tilecaches.each do |cache|
47 cache.ipaddresses(:family => :inet, :role => :external).sort.each do |address|
48 firewall_rule "accept-squid" do
51 source "net:#{address}"
58 firewall_rule "accept-squid-icp" do
61 source "net:#{address}"
68 firewall_rule "accept-squid-icp-reply" do
78 firewall_rule "accept-squid-htcp" do
81 source "net:#{address}"
88 firewall_rule "accept-squid-htcp-reply" do
100 squid_fragment "tilecache" do
101 template "squid.conf.erb"
102 variables :caches => tilecaches, :renders => tilerenders
107 template "/etc/logrotate.d/squid" do
108 source "logrotate.squid.erb"
114 nginx_site "default" do
118 template "/usr/local/bin/nginx_generate_tilecache_qos_map" do
119 source "nginx_generate_tilecache_qos_map.erb"
123 variables :totp_key => web_passwords["totp_key"]
126 template "/etc/cron.d/tilecache" do
133 execute "execute_nginx_generate_tilecache_qos_map" do
134 command "/usr/local/bin/nginx_generate_tilecache_qos_map"
135 creates "/etc/nginx/conf.d/tile_qos_rates.map"
139 ssl_certificate "tile.openstreetmap.org" do
140 domains ["tile.openstreetmap.org",
141 "a.tile.openstreetmap.org",
142 "b.tile.openstreetmap.org",
143 "c.tile.openstreetmap.org",
148 notifies :restart, "service[nginx]"
152 template "nginx_tile.conf.erb"
153 variables :caches => tilecaches
156 template "/etc/logrotate.d/nginx" do
157 source "logrotate.nginx.erb"
163 fail2ban_jail "squid" do
167 tilerenders.each do |render|
168 munin_plugin "ping_#{render[:fqdn]}" do
170 conf "munin.ping.erb"
171 conf_variables :host => render[:fqdn]
175 template "/etc/cron.d/tilecache" do
182 directory "/srv/tilecache" do
188 directory "/srv/tilecache/data" do
194 cookbook_file "/srv/tilecache/tilecache-curl-time.txt" do
195 source "tilecache-curl-time.txt"
201 template "/srv/tilecache/tilecache-curl-time" do
202 source "tilecache-curl-time.erb"
206 variables :caches => tilecaches, :renders => tilerenders
209 file "/srv/tilecache/tilecache-fastest-peers" do
213 ohai_plugin "tilecache" do
214 template "ohai.rb.erb"