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 "accounts"
21 include_recipe "apache"
23 include_recipe "munin"
24 include_recipe "nodejs"
25 include_recipe "postgresql"
26 include_recipe "prometheus"
27 include_recipe "python"
29 include_recipe "tools"
31 blocks = data_bag_item("tile", "blocks")
32 admins = data_bag_item("apache", "admins")
33 web_passwords = data_bag_item("web", "passwords")
37 apache_module "expires"
38 apache_module "headers"
39 apache_module "remoteip"
40 apache_module "rewrite"
42 apache_module "tile" do
46 apache_conf "renderd" do
50 ssl_certificate node[:fqdn] do
51 domains [node[:fqdn], "tile.openstreetmap.org", "render.openstreetmap.org"]
52 notifies :reload, "service[apache2]"
55 remote_file "#{Chef::Config[:file_cache_path]}/fastly-ip-list.json" do
56 source "https://api.fastly.com/public-ip-list"
61 fastlyips = JSON.parse(IO.read("#{Chef::Config[:file_cache_path]}/fastly-ip-list.json"))
63 remote_file "#{Chef::Config[:file_cache_path]}/statuscake-locations.json" do
64 source "https://app.statuscake.com/Workfloor/Locations.php?format=json"
69 statuscakelocations = JSON.parse(IO.read("#{Chef::Config[:file_cache_path]}/statuscake-locations.json"))
71 apache_site "default" do
75 apache_site "tileserver_site" do
79 apache_site "tile.openstreetmap.org" do
81 variables :fastly => fastlyips["addresses"] + fastlyips["ipv6_addresses"],
82 :statuscake => statuscakelocations.flat_map { |_, v| [v["ip"], v["ipv6"]] },
83 :admins => admins["hosts"]
86 template "/etc/logrotate.d/apache2" do
87 source "logrotate.apache.erb"
93 directory "/srv/tile.openstreetmap.org" do
99 directory "/srv/tile.openstreetmap.org/conf" do
105 file "/srv/tile.openstreetmap.org/conf/ip.map" do
113 systemd_service "renderd" do
115 after "postgresql.service"
116 wants "postgresql.service"
121 protect_system "full"
123 no_new_privileges true
127 systemd_service "renderd" do
132 action [:enable, :start]
133 subscribes :restart, "systemd_service[renderd]"
136 directory "/srv/tile.openstreetmap.org/tiles" do
142 template "/etc/renderd.conf" do
143 source "renderd.conf.erb"
147 notifies :reload, "service[apache2]"
148 notifies :restart, "service[renderd]"
151 remote_directory "/srv/tile.openstreetmap.org/html" do
161 template "/srv/tile.openstreetmap.org/html/index.html" do
162 source "index.html.erb"
175 python_package "pyotp" do
179 unifont = if node[:lsb][:release].to_f < 22.04
193 ["NotoSansArabicUI-Regular.ttf", "NotoSansArabicUI-Bold.ttf"].each do |font|
194 remote_file "/usr/share/fonts/truetype/noto/#{font}" do
195 action :create_if_missing
196 source "https://github.com/googlei18n/noto-fonts/raw/master/hinted/#{font}"
203 directory "/srv/tile.openstreetmap.org/cgi-bin" do
209 template "/srv/tile.openstreetmap.org/cgi-bin/export" do
214 variables :blocks => blocks, :totp_key => web_passwords["totp_key"]
217 template "/srv/tile.openstreetmap.org/cgi-bin/debug" do
224 template "/etc/cron.hourly/export" do
225 source "export.cron.erb"
231 directory "/srv/tile.openstreetmap.org/data" do
237 package "mapnik-utils"
239 node[:tile][:data].each_value do |data|
241 file = "/srv/tile.openstreetmap.org/data/#{File.basename(url)}"
244 directory = "/srv/tile.openstreetmap.org/data/#{data[:directory]}"
246 directory directory do
252 directory = "/srv/tile.openstreetmap.org/data"
260 command "tar -zxf #{file} -C #{directory}"
264 elsif file =~ /\.tar\.bz2$/
269 command "tar -jxf #{file} -C #{directory}"
273 elsif file =~ /\.zip$/
278 command "unzip -qq -o #{file} -d #{directory}"
284 execute "#{file}_shapeindex" do
286 command "find #{directory} -type f -iname '*.shp' -print0 | xargs -0 --no-run-if-empty shapeindex --shape_files"
289 subscribes :run, "execute[#{file}]", :immediately
295 use_conditional_get true
298 action :create_if_missing
306 notifies :run, "execute[#{file}]", :immediately
307 notifies :restart, "service[renderd]"
311 nodejs_package "carto"
313 systemd_service "update-lowzoom@" do
314 description "Low zoom tile update service for %i layer"
315 conflicts "render-lowzoom.service"
317 exec_start "/bin/bash /usr/local/bin/update-lowzoom-%i"
318 runtime_directory "update-lowzoom-%i"
322 protect_system "full"
324 no_new_privileges true
328 directory "/srv/tile.openstreetmap.org/styles" do
334 node[:tile][:styles].each do |name, details|
335 style_directory = "/srv/tile.openstreetmap.org/styles/#{name}"
336 tile_directory = "/srv/tile.openstreetmap.org/tiles/#{name}"
338 template "/usr/local/bin/update-lowzoom-#{name}" do
339 source "update-lowzoom.erb"
343 variables :style => name
346 service "update-lowzoom@#{name}" do
348 supports :restart => true
351 directory tile_directory do
357 details[:tile_directories].each do |directory|
358 directory directory[:name] do
364 directory[:min_zoom].upto(directory[:max_zoom]) do |zoom|
365 directory "#{directory[:name]}/#{zoom}" do
371 link "#{tile_directory}/#{zoom}" do
372 to "#{directory[:name]}/#{zoom}"
379 file "#{tile_directory}/planet-import-complete" do
380 action :create_if_missing
386 git style_directory do
388 repository details[:repository]
389 revision details[:revision]
394 link "#{style_directory}/data" do
395 to "/srv/tile.openstreetmap.org/data"
400 execute "#{style_directory}/project.mml" do
402 command "carto -a 3.0.0 project.mml > project.xml"
406 subscribes :run, "git[#{style_directory}]"
407 notifies :restart, "service[renderd]", :immediately
408 notifies :restart, "service[update-lowzoom@#{name}]"
412 postgresql_version = node[:tile][:database][:cluster].split("/").first
413 postgis_version = node[:tile][:database][:postgis]
415 package "postgresql-#{postgresql_version}-postgis-#{postgis_version}"
417 postgresql_user "jburgess" do
418 cluster node[:tile][:database][:cluster]
422 postgresql_user "tomh" do
423 cluster node[:tile][:database][:cluster]
427 postgresql_user "tile" do
428 cluster node[:tile][:database][:cluster]
431 postgresql_user "www-data" do
432 cluster node[:tile][:database][:cluster]
435 postgresql_user "_renderd" do
436 cluster node[:tile][:database][:cluster]
439 postgresql_database "gis" do
440 cluster node[:tile][:database][:cluster]
444 postgresql_extension "postgis" do
445 cluster node[:tile][:database][:cluster]
449 postgresql_extension "hstore" do
450 cluster node[:tile][:database][:cluster]
452 only_if { node[:tile][:database][:hstore] }
455 %w[geography_columns planet_osm_nodes planet_osm_rels planet_osm_ways raster_columns raster_overviews spatial_ref_sys].each do |table|
456 postgresql_table table do
457 cluster node[:tile][:database][:cluster]
460 permissions "tile" => :all
464 %w[geometry_columns planet_osm_line planet_osm_point planet_osm_polygon planet_osm_roads].each do |table|
465 postgresql_table table do
466 cluster node[:tile][:database][:cluster]
469 permissions "tile" => :all, "www-data" => :select, "_renderd" => :select
479 if node[:tile][:database][:external_data_script]
480 execute node[:tile][:database][:external_data_script] do
481 command "#{node[:tile][:database][:external_data_script]} -R _renderd"
482 cwd "/srv/tile.openstreetmap.org"
488 Array(node[:tile][:database][:external_data_tables]).each do |table|
489 postgresql_table table do
490 cluster node[:tile][:database][:cluster]
493 permissions "tile" => :all, "www-data" => :select, "_renderd" => :select
498 postgresql_munin "gis" do
499 cluster node[:tile][:database][:cluster]
503 directory File.dirname(node[:tile][:database][:node_file]) do
510 file node[:tile][:database][:node_file] do
516 directory "/var/log/tile" do
529 gem_package "apachelogregex" do
530 gem_binary node[:ruby][:gem]
533 gem_package "file-tail" do
534 gem_binary node[:ruby][:gem]
537 gem_package "lru_redux" do
538 gem_binary node[:ruby][:gem]
541 remote_directory "/usr/local/bin" do
551 template "/usr/local/bin/tile-ratelimit" do
552 source "tile-ratelimit.erb"
558 systemd_service "tile-ratelimit" do
559 description "Monitor tile requests and enforce rate limits"
560 after "apache2.service"
563 exec_start "/usr/local/bin/tile-ratelimit"
567 protect_system "full"
569 read_write_paths "/srv/tile.openstreetmap.org/conf"
570 no_new_privileges true
574 service "tile-ratelimit" do
575 action [:enable, :start]
576 subscribes :restart, "file[/usr/local/bin/tile-ratelimit]"
577 subscribes :restart, "systemd_service[tile-ratelimit]"
580 template "/usr/local/bin/expire-tiles" do
581 source "expire-tiles.erb"
587 directory "/var/lib/replicate" do
593 directory "/var/lib/replicate/expire-queue" do
599 template "/usr/local/bin/replicate" do
600 source "replicate.erb"
604 variables :postgresql_version => postgresql_version.to_f
607 systemd_service "expire-tiles" do
608 description "Tile dirtying service"
611 exec_start "/usr/local/bin/expire-tiles"
612 standard_output "null"
615 protect_system "full"
617 no_new_privileges true
620 systemd_path "expire-tiles" do
621 description "Tile dirtying trigger"
622 directory_not_empty "/var/lib/replicate/expire-queue"
625 service "expire-tiles.path" do
626 action [:enable, :start]
627 subscribes :restart, "systemd_path[expire-tiles]"
630 systemd_service "replicate" do
631 description "Rendering database replication service"
632 after "postgresql.service"
633 wants "postgresql.service"
635 exec_start "/usr/local/bin/replicate"
638 protect_system "full"
640 no_new_privileges true
644 service "replicate" do
645 action [:enable, :start]
646 subscribes :restart, "template[/usr/local/bin/replicate]"
647 subscribes :restart, "systemd_service[replicate]"
650 template "/etc/logrotate.d/replicate" do
651 source "replicate.logrotate.erb"
657 template "/usr/local/bin/render-lowzoom" do
658 source "render-lowzoom.erb"
664 systemd_service "render-lowzoom" do
665 description "Render low zoom tiles"
666 condition_path_exists_glob "!/run/update-lowzoom-*"
668 exec_start "/usr/local/bin/render-lowzoom"
672 protect_system "full"
674 no_new_privileges true
677 systemd_timer "render-lowzoom" do
678 description "Render low zoom tiles"
679 on_calendar "Fri *-*-* 23:00:00 UTC"
682 service "render-lowzoom.timer" do
683 action [:enable, :start]
686 package "liblockfile-simple-perl"
687 package "libfilesys-df-perl"
689 template "/usr/local/bin/cleanup-tiles" do
690 source "cleanup-tiles.erb"
696 tile_directories = node[:tile][:styles].collect do |_, style|
697 style[:tile_directories].collect { |directory| directory[:name] }
698 end.flatten.sort.uniq
700 tile_directories.each do |directory|
701 label = directory.gsub("/", "-")
703 cron_d "cleanup-tiles#{label}" do
706 command "ionice -c 3 /usr/local/bin/cleanup-tiles #{directory}"
707 mailto "admins@openstreetmap.org"
711 munin_plugin "mod_tile_fresh"
712 munin_plugin "mod_tile_latency"
713 munin_plugin "mod_tile_response"
714 munin_plugin "mod_tile_zoom"
716 munin_plugin "renderd_processed"
717 munin_plugin "renderd_queue"
718 munin_plugin "renderd_queue_time"
719 munin_plugin "renderd_zoom"
720 munin_plugin "renderd_zoom_time"
722 munin_plugin "replication_delay"
724 package "ruby-webrick"
726 prometheus_exporter "modtile" do
730 prometheus_exporter "renderd" do