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 web_passwords = data_bag_item("web", "passwords")
36 apache_module "expires"
37 apache_module "headers"
38 apache_module "remoteip"
39 apache_module "rewrite"
41 apache_module "tile" do
45 apache_conf "renderd" do
49 ssl_certificate node[:fqdn] do
50 domains [node[:fqdn], "tile.openstreetmap.org", "render.openstreetmap.org"]
51 notifies :reload, "service[apache2]"
54 remote_file "#{Chef::Config[:file_cache_path]}/fastly-ip-list.json" do
55 source "https://api.fastly.com/public-ip-list"
60 fastlyips = JSON.parse(IO.read("#{Chef::Config[:file_cache_path]}/fastly-ip-list.json"))
62 apache_site "default" do
66 apache_site "tileserver_site" do
70 apache_site "tile.openstreetmap.org" do
72 variables :fastly => fastlyips["addresses"]
75 template "/etc/logrotate.d/apache2" do
76 source "logrotate.apache.erb"
82 directory "/srv/tile.openstreetmap.org" do
88 directory "/srv/tile.openstreetmap.org/conf" do
94 file "/srv/tile.openstreetmap.org/conf/ip.map" do
102 systemd_service "renderd" do
104 after "postgresql.service"
105 wants "postgresql.service"
110 protect_system "full"
112 no_new_privileges true
116 systemd_service "renderd" do
121 action [:enable, :start]
122 subscribes :restart, "systemd_service[renderd]"
125 directory "/srv/tile.openstreetmap.org/tiles" do
131 template "/etc/renderd.conf" do
132 source "renderd.conf.erb"
136 notifies :reload, "service[apache2]"
137 notifies :restart, "service[renderd]"
140 remote_directory "/srv/tile.openstreetmap.org/html" do
150 template "/srv/tile.openstreetmap.org/html/index.html" do
151 source "index.html.erb"
163 python_package "pyotp" do
167 unifont = if node[:lsb][:release].to_f < 22.04
181 ["NotoSansArabicUI-Regular.ttf", "NotoSansArabicUI-Bold.ttf"].each do |font|
182 remote_file "/usr/share/fonts/truetype/noto/#{font}" do
183 action :create_if_missing
184 source "https://github.com/googlei18n/noto-fonts/raw/master/hinted/#{font}"
191 directory "/srv/tile.openstreetmap.org/cgi-bin" do
197 template "/srv/tile.openstreetmap.org/cgi-bin/export" do
202 variables :blocks => blocks, :totp_key => web_passwords["totp_key"]
205 template "/srv/tile.openstreetmap.org/cgi-bin/debug" do
212 template "/etc/cron.hourly/export" do
213 source "export.cron.erb"
219 directory "/srv/tile.openstreetmap.org/data" do
225 package "mapnik-utils"
227 node[:tile][:data].each_value do |data|
229 file = "/srv/tile.openstreetmap.org/data/#{File.basename(url)}"
232 directory = "/srv/tile.openstreetmap.org/data/#{data[:directory]}"
234 directory directory do
240 directory = "/srv/tile.openstreetmap.org/data"
248 command "tar -zxf #{file} -C #{directory}"
252 elsif file =~ /\.tar\.bz2$/
257 command "tar -jxf #{file} -C #{directory}"
261 elsif file =~ /\.zip$/
266 command "unzip -qq -o #{file} -d #{directory}"
272 execute "#{file}_shapeindex" do
274 command "find #{directory} -type f -iname '*.shp' -print0 | xargs -0 --no-run-if-empty shapeindex --shape_files"
277 subscribes :run, "execute[#{file}]", :immediately
283 use_conditional_get true
286 action :create_if_missing
294 notifies :run, "execute[#{file}]", :immediately
295 notifies :restart, "service[renderd]"
299 nodejs_package "carto"
301 systemd_service "update-lowzoom@" do
302 description "Low zoom tile update service for %i layer"
303 conflicts "render-lowzoom.service"
305 exec_start "/bin/bash /usr/local/bin/update-lowzoom-%i"
306 runtime_directory "update-lowzoom-%i"
310 protect_system "full"
312 no_new_privileges true
316 directory "/srv/tile.openstreetmap.org/styles" do
322 node[:tile][:styles].each do |name, details|
323 style_directory = "/srv/tile.openstreetmap.org/styles/#{name}"
324 tile_directory = "/srv/tile.openstreetmap.org/tiles/#{name}"
326 template "/usr/local/bin/update-lowzoom-#{name}" do
327 source "update-lowzoom.erb"
331 variables :style => name
334 service "update-lowzoom@#{name}" do
336 supports :restart => true
339 directory tile_directory do
345 details[:tile_directories].each do |directory|
346 directory directory[:name] do
352 directory[:min_zoom].upto(directory[:max_zoom]) do |zoom|
353 directory "#{directory[:name]}/#{zoom}" do
359 link "#{tile_directory}/#{zoom}" do
360 to "#{directory[:name]}/#{zoom}"
367 file "#{tile_directory}/planet-import-complete" do
368 action :create_if_missing
374 git style_directory do
376 repository details[:repository]
377 revision details[:revision]
382 link "#{style_directory}/data" do
383 to "/srv/tile.openstreetmap.org/data"
388 execute "#{style_directory}/project.mml" do
390 command "carto -a 3.0.0 project.mml > project.xml"
394 subscribes :run, "git[#{style_directory}]"
395 notifies :restart, "service[renderd]", :immediately
396 notifies :restart, "service[update-lowzoom@#{name}]"
400 postgresql_version = node[:tile][:database][:cluster].split("/").first
401 postgis_version = node[:tile][:database][:postgis]
403 package "postgresql-#{postgresql_version}-postgis-#{postgis_version}"
405 postgresql_user "jburgess" do
406 cluster node[:tile][:database][:cluster]
410 postgresql_user "tomh" do
411 cluster node[:tile][:database][:cluster]
415 postgresql_user "tile" do
416 cluster node[:tile][:database][:cluster]
419 postgresql_user "www-data" do
420 cluster node[:tile][:database][:cluster]
423 postgresql_user "_renderd" do
424 cluster node[:tile][:database][:cluster]
427 postgresql_database "gis" do
428 cluster node[:tile][:database][:cluster]
432 postgresql_extension "postgis" do
433 cluster node[:tile][:database][:cluster]
437 postgresql_extension "hstore" do
438 cluster node[:tile][:database][:cluster]
440 only_if { node[:tile][:database][:hstore] }
443 %w[geography_columns planet_osm_nodes planet_osm_rels planet_osm_ways raster_columns raster_overviews spatial_ref_sys].each do |table|
444 postgresql_table table do
445 cluster node[:tile][:database][:cluster]
448 permissions "tile" => :all
452 %w[geometry_columns planet_osm_line planet_osm_point planet_osm_polygon planet_osm_roads].each do |table|
453 postgresql_table table do
454 cluster node[:tile][:database][:cluster]
457 permissions "tile" => :all, "www-data" => :select, "_renderd" => :select
467 if node[:tile][:database][:external_data_script]
468 execute node[:tile][:database][:external_data_script] do
469 command "#{node[:tile][:database][:external_data_script]} -R _renderd"
470 cwd "/srv/tile.openstreetmap.org"
476 Array(node[:tile][:database][:external_data_tables]).each do |table|
477 postgresql_table table do
478 cluster node[:tile][:database][:cluster]
481 permissions "tile" => :all, "www-data" => :select, "_renderd" => :select
486 postgresql_munin "gis" do
487 cluster node[:tile][:database][:cluster]
491 directory File.dirname(node[:tile][:database][:node_file]) do
498 file node[:tile][:database][:node_file] do
504 directory "/var/log/tile" do
517 gem_package "apachelogregex" do
518 gem_binary node[:ruby][:gem]
521 gem_package "file-tail" do
522 gem_binary node[:ruby][:gem]
525 gem_package "lru_redux" do
526 gem_binary node[:ruby][:gem]
529 remote_directory "/usr/local/bin" do
539 template "/usr/local/bin/tile-ratelimit" do
540 source "tile-ratelimit.erb"
546 systemd_service "tile-ratelimit" do
547 description "Monitor tile requests and enforce rate limits"
548 after "apache2.service"
551 exec_start "/usr/local/bin/tile-ratelimit"
555 protect_system "full"
557 read_write_paths "/srv/tile.openstreetmap.org/conf"
558 no_new_privileges true
562 service "tile-ratelimit" do
563 action [:enable, :start]
564 subscribes :restart, "file[/usr/local/bin/tile-ratelimit]"
565 subscribes :restart, "systemd_service[tile-ratelimit]"
568 template "/usr/local/bin/expire-tiles" do
569 source "expire-tiles.erb"
575 directory "/var/lib/replicate" do
581 directory "/var/lib/replicate/expire-queue" do
587 template "/usr/local/bin/replicate" do
588 source "replicate.erb"
592 variables :postgresql_version => postgresql_version.to_f
595 systemd_service "expire-tiles" do
596 description "Tile dirtying service"
599 exec_start "/usr/local/bin/expire-tiles"
600 standard_output "null"
603 protect_system "full"
605 no_new_privileges true
608 systemd_path "expire-tiles" do
609 description "Tile dirtying trigger"
610 directory_not_empty "/var/lib/replicate/expire-queue"
613 service "expire-tiles.path" do
614 action [:enable, :start]
615 subscribes :restart, "systemd_path[expire-tiles]"
618 systemd_service "replicate" do
619 description "Rendering database replication service"
620 after "postgresql.service"
621 wants "postgresql.service"
623 exec_start "/usr/local/bin/replicate"
626 protect_system "full"
628 no_new_privileges true
632 service "replicate" do
633 action [:enable, :start]
634 subscribes :restart, "template[/usr/local/bin/replicate]"
635 subscribes :restart, "systemd_service[replicate]"
638 template "/etc/logrotate.d/replicate" do
639 source "replicate.logrotate.erb"
645 template "/usr/local/bin/render-lowzoom" do
646 source "render-lowzoom.erb"
652 systemd_service "render-lowzoom" do
653 description "Render low zoom tiles"
654 condition_path_exists_glob "!/run/update-lowzoom-*"
656 exec_start "/usr/local/bin/render-lowzoom"
660 protect_system "full"
662 no_new_privileges true
665 systemd_timer "render-lowzoom" do
666 description "Render low zoom tiles"
667 on_calendar "Fri *-*-* 23:00:00 UTC"
670 service "render-lowzoom.timer" do
671 action [:enable, :start]
674 package "liblockfile-simple-perl"
675 package "libfilesys-df-perl"
677 template "/usr/local/bin/cleanup-tiles" do
678 source "cleanup-tiles.erb"
684 tile_directories = node[:tile][:styles].collect do |_, style|
685 style[:tile_directories].collect { |directory| directory[:name] }
686 end.flatten.sort.uniq
688 tile_directories.each do |directory|
689 label = directory.gsub("/", "-")
691 cron_d "cleanup-tiles#{label}" do
694 command "ionice -c 3 /usr/local/bin/cleanup-tiles #{directory}"
695 mailto "admins@openstreetmap.org"
699 munin_plugin "mod_tile_fresh"
700 munin_plugin "mod_tile_latency"
701 munin_plugin "mod_tile_response"
702 munin_plugin "mod_tile_zoom"
704 munin_plugin "renderd_processed"
705 munin_plugin "renderd_queue"
706 munin_plugin "renderd_queue_time"
707 munin_plugin "renderd_zoom"
708 munin_plugin "renderd_zoom_time"
710 munin_plugin "replication_delay"
712 package "ruby-webrick"
714 prometheus_exporter "modtile" do
718 prometheus_exporter "renderd" do