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 file "/etc/cron.d/tilecache" do
130 cron_d "tilecache-generate-qos-map" do
133 command "/usr/local/bin/nginx_generate_tilecache_qos_map"
136 cron_d "tilecache-curl-time" do
138 command "/srv/tilecache/tilecache-curl-time"
141 cron_d "tilecache-curl-time-cleanup" do
145 command "/srv/tilecache/tilecache-curl-time-cleanup"
148 execute "execute_nginx_generate_tilecache_qos_map" do
149 command "/usr/local/bin/nginx_generate_tilecache_qos_map"
150 creates "/etc/nginx/conf.d/tile_qos_rates.map"
154 ssl_certificate "tile.openstreetmap.org" do
155 domains ["tile.openstreetmap.org",
156 "a.tile.openstreetmap.org",
157 "b.tile.openstreetmap.org",
158 "c.tile.openstreetmap.org",
163 notifies :restart, "service[nginx]"
167 template "nginx_tile.conf.erb"
168 variables :caches => tilecaches
171 template "/etc/logrotate.d/nginx" do
172 source "logrotate.nginx.erb"
178 fail2ban_jail "squid" do
182 tilerenders.each do |render|
183 munin_plugin "ping_#{render[:fqdn]}" do
185 conf "munin.ping.erb"
186 conf_variables :host => render[:fqdn]
190 directory "/srv/tilecache" do
196 directory "/srv/tilecache/data" do
202 cookbook_file "/srv/tilecache/tilecache-curl-time.txt" do
203 source "tilecache-curl-time.txt"
209 template "/srv/tilecache/tilecache-curl-time" do
210 source "tilecache-curl-time.erb"
214 variables :caches => tilecaches, :renders => tilerenders
217 template "/srv/tilecache/tilecache-curl-time-cleanup" do
218 source "tilecache-curl-time-cleanup.erb"
224 ohai_plugin "tilecache" do
225 template "ohai.rb.erb"