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"
37 # oathtool for QoS token
40 tilecaches = search(:node, "roles:tilecache").sort_by { |n| n[:hostname] }
41 tilerenders = search(:node, "roles:tile").sort_by { |n| n[:hostname] }
43 web_passwords = data_bag_item("web", "passwords")
45 tilecaches.each do |cache|
46 cache.ipaddresses(:family => :inet, :role => :external).sort.each do |address|
47 firewall_rule "accept-squid" do
50 source "net:#{address}"
57 firewall_rule "accept-squid-icp" do
60 source "net:#{address}"
67 firewall_rule "accept-squid-icp-reply" do
77 firewall_rule "accept-squid-htcp" do
80 source "net:#{address}"
87 firewall_rule "accept-squid-htcp-reply" do
99 squid_fragment "tilecache" do
100 template "squid.conf.erb"
101 variables :caches => tilecaches, :renders => tilerenders
106 template "/etc/logrotate.d/squid" do
107 source "logrotate.squid.erb"
113 nginx_site "default" do
117 template "/usr/local/bin/nginx_generate_tilecache_qos_map" do
118 source "nginx_generate_tilecache_qos_map.erb"
122 variables :totp_key => web_passwords["totp_key"]
125 template "/etc/cron.d/tilecache" do
132 execute "execute_nginx_generate_tilecache_qos_map" do
133 command "/usr/local/bin/nginx_generate_tilecache_qos_map"
134 creates "/etc/nginx/conf.d/tile_qos_rates.map"
138 ssl_certificate "tile.openstreetmap.org" do
139 domains ["tile.openstreetmap.org",
140 "a.tile.openstreetmap.org",
141 "b.tile.openstreetmap.org",
142 "c.tile.openstreetmap.org",
147 notifies :restart, "service[nginx]"
151 template "nginx_tile.conf.erb"
152 variables :caches => tilecaches
155 template "/etc/logrotate.d/nginx" do
156 source "logrotate.nginx.erb"
162 fail2ban_jail "squid" do
166 tilerenders.each do |render|
167 munin_plugin "ping_#{render[:fqdn]}" do
169 conf "munin.ping.erb"
170 conf_variables :host => render[:fqdn]