5 # Copyright 2013, 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.
20 include_recipe "apache"
22 include_recipe "nodejs"
23 include_recipe "postgresql"
24 include_recipe "python"
25 include_recipe "tools"
27 blocks = data_bag_item("tile", "blocks")
28 web_passwords = data_bag_item("web", "passwords")
32 apache_module "expires"
33 apache_module "headers"
34 apache_module "remoteip"
35 apache_module "rewrite"
37 apache_module "tile" do
41 ssl_certificate node[:fqdn] do
42 domains [node[:fqdn], "tile.openstreetmap.org", "render.openstreetmap.org"]
43 notifies :reload, "service[apache2]"
46 tilecaches = search(:node, "roles:tilecache").sort_by { |n| n[:hostname] }
48 apache_site "default" do
52 apache_site "tile.openstreetmap.org" do
54 variables :caches => tilecaches
57 template "/etc/logrotate.d/apache2" do
58 source "logrotate.apache.erb"
64 directory "/srv/tile.openstreetmap.org" do
72 systemd_service "renderd" do
73 description "Mapnik rendering daemon"
74 after "postgresql.service"
75 wants "postgresql.service"
77 exec_start "/usr/bin/renderd -f"
78 runtime_directory "renderd"
85 no_new_privileges true
90 action [:enable, :start]
91 subscribes :restart, "systemd_service[renderd]"
94 directory "/srv/tile.openstreetmap.org/tiles" do
100 template "/etc/renderd.conf" do
101 source "renderd.conf.erb"
105 notifies :reload, "service[apache2]"
106 notifies :restart, "service[renderd]"
109 remote_directory "/srv/tile.openstreetmap.org/html" do
119 template "/srv/tile.openstreetmap.org/html/index.html" do
120 source "index.html.erb"
132 python_package "pyotp"
142 ["NotoSansArabicUI-Regular.ttf", "NotoSansArabicUI-Bold.ttf"].each do |font|
143 remote_file "/usr/share/fonts/truetype/noto/#{font}" do
144 action :create_if_missing
145 source "https://github.com/googlei18n/noto-fonts/raw/master/hinted/#{font}"
152 directory "/srv/tile.openstreetmap.org/cgi-bin" do
158 template "/srv/tile.openstreetmap.org/cgi-bin/export" do
163 variables :blocks => blocks, :totp_key => web_passwords["totp_key"]
166 template "/srv/tile.openstreetmap.org/cgi-bin/debug" do
173 template "/etc/cron.hourly/export" do
174 source "export.cron.erb"
180 directory "/srv/tile.openstreetmap.org/data" do
186 package "mapnik-utils"
188 node[:tile][:data].each_value do |data|
190 file = "/srv/tile.openstreetmap.org/data/#{File.basename(url)}"
193 directory = "/srv/tile.openstreetmap.org/data/#{data[:directory]}"
195 directory directory do
201 directory = "/srv/tile.openstreetmap.org/data"
209 command "tar -zxf #{file} -C #{directory}"
213 elsif file =~ /\.tar\.bz2$/
218 command "tar -jxf #{file} -C #{directory}"
222 elsif file =~ /\.zip$/
227 command "unzip -qq -o #{file} -d #{directory}"
233 execute "#{file}_shapeindex" do
235 command "find #{directory} -type f -iname '*.shp' -print0 | xargs -0 --no-run-if-empty shapeindex --shape_files"
238 subscribes :run, "execute[#{file}]", :immediately
244 use_conditional_get true
247 action :create_if_missing
255 notifies :run, "execute[#{file}]", :immediately
256 notifies :restart, "service[renderd]"
260 nodejs_package "carto"
261 nodejs_package "millstone"
263 systemd_service "update-lowzoom@" do
264 description "Low zoom tile update service for %i layer"
266 exec_start "/bin/bash /usr/local/bin/update-lowzoom-%i"
270 protect_system "full"
272 no_new_privileges true
276 directory "/srv/tile.openstreetmap.org/styles" do
282 node[:tile][:styles].each do |name, details|
283 style_directory = "/srv/tile.openstreetmap.org/styles/#{name}"
284 tile_directory = "/srv/tile.openstreetmap.org/tiles/#{name}"
286 template "/usr/local/bin/update-lowzoom-#{name}" do
287 source "update-lowzoom.erb"
291 variables :style => name
294 service "update-lowzoom@#{name}" do
296 supports :restart => true
299 directory tile_directory do
305 details[:tile_directories].each do |directory|
306 directory directory[:name] do
312 directory[:min_zoom].upto(directory[:max_zoom]) do |zoom|
313 directory "#{directory[:name]}/#{zoom}" do
319 link "#{tile_directory}/#{zoom}" do
320 to "#{directory[:name]}/#{zoom}"
327 file "#{tile_directory}/planet-import-complete" do
328 action :create_if_missing
334 git style_directory do
336 repository details[:repository]
337 revision details[:revision]
342 link "#{style_directory}/data" do
343 to "/srv/tile.openstreetmap.org/data"
348 execute "#{style_directory}/project.mml" do
350 command "carto -a 3.0.0 project.mml > project.xml"
354 subscribes :run, "git[#{style_directory}]"
355 notifies :restart, "service[renderd]", :immediately
356 notifies :restart, "service[update-lowzoom@#{name}]"
360 postgresql_version = node[:tile][:database][:cluster].split("/").first
361 postgis_version = node[:tile][:database][:postgis]
364 package "postgresql-#{postgresql_version}-postgis-#{postgis_version}"
366 postgresql_user "jburgess" do
367 cluster node[:tile][:database][:cluster]
371 postgresql_user "tomh" do
372 cluster node[:tile][:database][:cluster]
376 postgresql_user "tile" do
377 cluster node[:tile][:database][:cluster]
380 postgresql_user "www-data" do
381 cluster node[:tile][:database][:cluster]
384 postgresql_database "gis" do
385 cluster node[:tile][:database][:cluster]
389 postgresql_extension "postgis" do
390 cluster node[:tile][:database][:cluster]
394 postgresql_extension "hstore" do
395 cluster node[:tile][:database][:cluster]
399 %w[geography_columns planet_osm_nodes planet_osm_rels planet_osm_ways raster_columns raster_overviews spatial_ref_sys].each do |table|
400 postgresql_table table do
401 cluster node[:tile][:database][:cluster]
404 permissions "tile" => :all
408 %w[geometry_columns planet_osm_line planet_osm_point planet_osm_polygon planet_osm_roads].each do |table|
409 postgresql_table table do
410 cluster node[:tile][:database][:cluster]
413 permissions "tile" => :all, "www-data" => :select
417 postgresql_munin "gis" do
418 cluster node[:tile][:database][:cluster]
422 file node[:tile][:node_file] do
428 directory "/var/log/tile" do
439 if node[:lsb][:release].to_f >= 18.04
445 remote_directory "/usr/local/bin" do
455 template "/usr/local/bin/expire-tiles" do
456 source "expire-tiles.bionic.erb"
469 gem_package "proj4rb"
470 gem_package "libxml-ruby"
472 remote_directory "/usr/local/lib/site_ruby" do
482 template "/usr/local/bin/expire-tiles" do
483 source "expire-tiles.xenial.erb"
490 directory "/var/lib/replicate" do
496 directory "/var/lib/replicate/expire-queue" do
502 template "/var/lib/replicate/configuration.txt" do
503 source "replicate.configuration.erb"
509 template "/usr/local/bin/replicate" do
510 source "replicate.erb"
516 systemd_service "expire-tiles" do
517 description "Tile dirtying service"
520 exec_start "/usr/local/bin/expire-tiles"
521 standard_output "null"
524 protect_system "full"
526 no_new_privileges true
529 systemd_path "expire-tiles" do
530 description "Tile dirtying trigger"
531 directory_not_empty "/var/lib/replicate/expire-queue"
534 service "expire-tiles.path" do
535 action [:enable, :start]
536 subscribes :restart, "systemd_path[expire-tiles]"
539 systemd_service "replicate" do
540 description "Rendering database replication service"
541 after "postgresql.service"
542 wants "postgresql.service"
544 exec_start "/usr/local/bin/replicate"
547 protect_system "full"
549 no_new_privileges true
553 service "replicate" do
554 action [:enable, :start]
555 subscribes :restart, "template[/usr/local/bin/replicate]"
556 subscribes :restart, "systemd_service[replicate]"
559 template "/etc/logrotate.d/replicate" do
560 source "replicate.logrotate.erb"
566 template "/usr/local/bin/render-lowzoom" do
567 source "render-lowzoom.erb"
573 template "/etc/cron.d/render-lowzoom" do
574 source "render-lowzoom.cron.erb"
580 package "liblockfile-simple-perl"
581 package "libfilesys-df-perl"
583 template "/usr/local/bin/cleanup-tiles" do
584 source "cleanup-tiles.erb"
590 tile_directories = node[:tile][:styles].collect do |_, style|
591 style[:tile_directories].collect { |directory| directory[:name] }
592 end.flatten.sort.uniq
594 template "/etc/cron.d/cleanup-tiles" do
595 source "cleanup-tiles.cron.erb"
599 variables :directories => tile_directories
602 munin_plugin "mod_tile_fresh"
603 munin_plugin "mod_tile_latency"
604 munin_plugin "mod_tile_response"
605 munin_plugin "mod_tile_zoom"
607 munin_plugin "renderd_processed"
608 munin_plugin "renderd_queue"
609 munin_plugin "renderd_queue_time"
610 munin_plugin "renderd_zoom"
611 munin_plugin "renderd_zoom_time"
613 munin_plugin "replication_delay" do