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.
 
  23 include_recipe "squid"
 
  24 include_recipe "nginx"
 
  25 include_recipe "fail2ban"
 
  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 web_passwords = data_bag_item("web", "passwords")
 
  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}"
 
  56     firewall_rule "accept-squid-icp" do
 
  59       source "net:#{address}"
 
  66     firewall_rule "accept-squid-icp-reply" do
 
  76     firewall_rule "accept-squid-htcp" do
 
  79       source "net:#{address}"
 
  86     firewall_rule "accept-squid-htcp-reply" do
 
  98 squid_fragment "tilecache" do
 
  99   template "squid.conf.erb"
 
 100   variables :caches => tilecaches, :renders => tilerenders
 
 105 template "/etc/logrotate.d/squid" do
 
 106   source "logrotate.squid.erb"
 
 112 # Configure cron with lower cpu and IO priority
 
 113 systemd_service "cron-load" do
 
 117   io_scheduling_class "best-effort"
 
 118   io_scheduling_priority 7
 
 119   notifies :restart, "service[cron]"
 
 122 nginx_site "default" do
 
 126 template "/usr/local/bin/nginx_generate_tilecache_qos_map" do
 
 127   source "nginx_generate_tilecache_qos_map.erb"
 
 131   variables :totp_key => web_passwords["totp_key"]
 
 134 template "/etc/cron.d/tilecache" do
 
 141 execute "execute_nginx_generate_tilecache_qos_map" do
 
 142   command "/usr/local/bin/nginx_generate_tilecache_qos_map"
 
 143   creates "/etc/nginx/conf.d/tile_qos_rates.map"
 
 147 ssl_certificate "tile.openstreetmap.org" do
 
 148   domains ["tile.openstreetmap.org",
 
 149            "a.tile.openstreetmap.org",
 
 150            "b.tile.openstreetmap.org",
 
 151            "c.tile.openstreetmap.org",
 
 156   notifies :restart, "service[nginx]"
 
 160   template "nginx_tile.conf.erb"
 
 161   variables :caches => tilecaches
 
 164 template "/etc/logrotate.d/nginx" do
 
 165   source "logrotate.nginx.erb"
 
 171 fail2ban_jail "squid" do
 
 175 tilerenders.each do |render|
 
 176   munin_plugin "ping_#{render[:fqdn]}" do
 
 178     conf "munin.ping.erb"
 
 179     conf_variables :host => render[:fqdn]