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"
28 include_recipe "tools"
30 blocks = data_bag_item("tile", "blocks")
31 web_passwords = data_bag_item("web", "passwords")
35 apache_module "expires"
36 apache_module "headers"
37 apache_module "remoteip"
38 apache_module "rewrite"
40 apache_module "tile" do
44 apache_conf "renderd" do
48 ssl_certificate node[:fqdn] do
49 domains [node[:fqdn], "tile.openstreetmap.org", "render.openstreetmap.org"]
50 notifies :reload, "service[apache2]"
53 remote_file "#{Chef::Config[:file_cache_path]}/fastly-ip-list.json" do
54 source "https://api.fastly.com/public-ip-list"
59 fastlyips = JSON.parse(IO.read("#{Chef::Config[:file_cache_path]}/fastly-ip-list.json"))
61 apache_site "default" do
65 apache_site "tileserver_site" do
69 apache_site "tile.openstreetmap.org" do
71 variables :fastly => fastlyips["addresses"]
74 template "/etc/logrotate.d/apache2" do
75 source "logrotate.apache.erb"
81 directory "/srv/tile.openstreetmap.org" do
87 directory "/srv/tile.openstreetmap.org/conf" do
93 file "/srv/tile.openstreetmap.org/conf/ip.map" do
101 systemd_service "renderd" do
103 after "postgresql.service"
104 wants "postgresql.service"
109 protect_system "full"
111 no_new_privileges true
115 systemd_service "renderd" do
120 action [:enable, :start]
121 subscribes :restart, "systemd_service[renderd]"
124 directory "/srv/tile.openstreetmap.org/tiles" do
130 template "/etc/renderd.conf" do
131 source "renderd.conf.erb"
135 notifies :reload, "service[apache2]"
136 notifies :restart, "service[renderd]"
139 remote_directory "/srv/tile.openstreetmap.org/html" do
149 template "/srv/tile.openstreetmap.org/html/index.html" do
150 source "index.html.erb"
162 python_package "pyotp" do
166 unifont = if node[:lsb][:release].to_f < 22.04
180 ["NotoSansArabicUI-Regular.ttf", "NotoSansArabicUI-Bold.ttf"].each do |font|
181 remote_file "/usr/share/fonts/truetype/noto/#{font}" do
182 action :create_if_missing
183 source "https://github.com/googlei18n/noto-fonts/raw/master/hinted/#{font}"
190 directory "/srv/tile.openstreetmap.org/cgi-bin" do
196 template "/srv/tile.openstreetmap.org/cgi-bin/export" do
201 variables :blocks => blocks, :totp_key => web_passwords["totp_key"]
204 template "/srv/tile.openstreetmap.org/cgi-bin/debug" do
211 template "/etc/cron.hourly/export" do
212 source "export.cron.erb"
218 directory "/srv/tile.openstreetmap.org/data" do
224 package "mapnik-utils"
226 node[:tile][:data].each_value do |data|
228 file = "/srv/tile.openstreetmap.org/data/#{File.basename(url)}"
231 directory = "/srv/tile.openstreetmap.org/data/#{data[:directory]}"
233 directory directory do
239 directory = "/srv/tile.openstreetmap.org/data"
247 command "tar -zxf #{file} -C #{directory}"
251 elsif file =~ /\.tar\.bz2$/
256 command "tar -jxf #{file} -C #{directory}"
260 elsif file =~ /\.zip$/
265 command "unzip -qq -o #{file} -d #{directory}"
271 execute "#{file}_shapeindex" do
273 command "find #{directory} -type f -iname '*.shp' -print0 | xargs -0 --no-run-if-empty shapeindex --shape_files"
276 subscribes :run, "execute[#{file}]", :immediately
282 use_conditional_get true
285 action :create_if_missing
293 notifies :run, "execute[#{file}]", :immediately
294 notifies :restart, "service[renderd]"
298 nodejs_package "carto"
300 systemd_service "update-lowzoom@" do
301 description "Low zoom tile update service for %i layer"
302 conflicts "render-lowzoom.service"
304 exec_start "/bin/bash /usr/local/bin/update-lowzoom-%i"
305 runtime_directory "update-lowzoom-%i"
309 protect_system "full"
311 no_new_privileges true
315 directory "/srv/tile.openstreetmap.org/styles" do
321 node[:tile][:styles].each do |name, details|
322 style_directory = "/srv/tile.openstreetmap.org/styles/#{name}"
323 tile_directory = "/srv/tile.openstreetmap.org/tiles/#{name}"
325 template "/usr/local/bin/update-lowzoom-#{name}" do
326 source "update-lowzoom.erb"
330 variables :style => name
333 service "update-lowzoom@#{name}" do
335 supports :restart => true
338 directory tile_directory do
344 details[:tile_directories].each do |directory|
345 directory directory[:name] do
351 directory[:min_zoom].upto(directory[:max_zoom]) do |zoom|
352 directory "#{directory[:name]}/#{zoom}" do
358 link "#{tile_directory}/#{zoom}" do
359 to "#{directory[:name]}/#{zoom}"
366 file "#{tile_directory}/planet-import-complete" do
367 action :create_if_missing
373 git style_directory do
375 repository details[:repository]
376 revision details[:revision]
381 link "#{style_directory}/data" do
382 to "/srv/tile.openstreetmap.org/data"
387 execute "#{style_directory}/project.mml" do
389 command "carto -a 3.0.0 project.mml > project.xml"
393 subscribes :run, "git[#{style_directory}]"
394 notifies :restart, "service[renderd]", :immediately
395 notifies :restart, "service[update-lowzoom@#{name}]"
399 postgresql_version = node[:tile][:database][:cluster].split("/").first
400 postgis_version = node[:tile][:database][:postgis]
402 package "postgresql-#{postgresql_version}-postgis-#{postgis_version}"
404 postgresql_user "jburgess" do
405 cluster node[:tile][:database][:cluster]
409 postgresql_user "tomh" do
410 cluster node[:tile][:database][:cluster]
414 postgresql_user "tile" do
415 cluster node[:tile][:database][:cluster]
418 postgresql_user "www-data" do
419 cluster node[:tile][:database][:cluster]
422 postgresql_user "_renderd" do
423 cluster node[:tile][:database][:cluster]
426 postgresql_database "gis" do
427 cluster node[:tile][:database][:cluster]
431 postgresql_extension "postgis" do
432 cluster node[:tile][:database][:cluster]
436 postgresql_extension "hstore" do
437 cluster node[:tile][:database][:cluster]
439 only_if { node[:tile][:database][:hstore] }
442 %w[geography_columns planet_osm_nodes planet_osm_rels planet_osm_ways raster_columns raster_overviews spatial_ref_sys].each do |table|
443 postgresql_table table do
444 cluster node[:tile][:database][:cluster]
447 permissions "tile" => :all
451 %w[geometry_columns planet_osm_line planet_osm_point planet_osm_polygon planet_osm_roads].each do |table|
452 postgresql_table table do
453 cluster node[:tile][:database][:cluster]
456 permissions "tile" => :all, "www-data" => :select, "_renderd" => :select
466 if node[:tile][:database][:external_data_script]
467 execute node[:tile][:database][:external_data_script] do
468 command "#{node[:tile][:database][:external_data_script]} -R _renderd"
469 cwd "/srv/tile.openstreetmap.org"
475 Array(node[:tile][:database][:external_data_tables]).each do |table|
476 postgresql_table table do
477 cluster node[:tile][:database][:cluster]
480 permissions "tile" => :all, "www-data" => :select, "_renderd" => :select
485 postgresql_munin "gis" do
486 cluster node[:tile][:database][:cluster]
490 directory File.dirname(node[:tile][:database][:node_file]) do
497 file node[:tile][:database][:node_file] do
503 directory "/var/log/tile" do
517 gem_package "apachelogregex"
518 gem_package "file-tail"
519 gem_package "lru_redux"
521 remote_directory "/usr/local/bin" do
531 template "/usr/local/bin/tile-ratelimit" do
532 source "tile-ratelimit.erb"
538 systemd_service "tile-ratelimit" do
539 description "Monitor tile requests and enforce rate limits"
540 after "apache2.service"
543 exec_start "/usr/local/bin/tile-ratelimit"
547 protect_system "full"
549 read_write_paths "/srv/tile.openstreetmap.org/conf"
550 no_new_privileges true
554 service "tile-ratelimit" do
555 action [:enable, :start]
556 subscribes :restart, "file[/usr/local/bin/tile-ratelimit]"
557 subscribes :restart, "systemd_service[tile-ratelimit]"
560 template "/usr/local/bin/expire-tiles" do
561 source "expire-tiles.erb"
567 directory "/var/lib/replicate" do
573 directory "/var/lib/replicate/expire-queue" do
579 template "/usr/local/bin/replicate" do
580 source "replicate.erb"
584 variables :postgresql_version => postgresql_version.to_f
587 systemd_service "expire-tiles" do
588 description "Tile dirtying service"
591 exec_start "/usr/local/bin/expire-tiles"
592 standard_output "null"
595 protect_system "full"
597 no_new_privileges true
600 systemd_path "expire-tiles" do
601 description "Tile dirtying trigger"
602 directory_not_empty "/var/lib/replicate/expire-queue"
605 service "expire-tiles.path" do
606 action [:enable, :start]
607 subscribes :restart, "systemd_path[expire-tiles]"
610 systemd_service "replicate" do
611 description "Rendering database replication service"
612 after "postgresql.service"
613 wants "postgresql.service"
615 exec_start "/usr/local/bin/replicate"
618 protect_system "full"
620 no_new_privileges true
624 service "replicate" do
625 action [:enable, :start]
626 subscribes :restart, "template[/usr/local/bin/replicate]"
627 subscribes :restart, "systemd_service[replicate]"
630 template "/etc/logrotate.d/replicate" do
631 source "replicate.logrotate.erb"
637 template "/usr/local/bin/render-lowzoom" do
638 source "render-lowzoom.erb"
644 systemd_service "render-lowzoom" do
645 description "Render low zoom tiles"
646 condition_path_exists_glob "!/run/update-lowzoom-*"
648 exec_start "/usr/local/bin/render-lowzoom"
652 protect_system "full"
654 no_new_privileges true
657 systemd_timer "render-lowzoom" do
658 description "Render low zoom tiles"
659 on_calendar "Sun *-*~07/1 01:00:00"
662 service "render-lowzoom.timer" do
663 action [:enable, :start]
666 package "liblockfile-simple-perl"
667 package "libfilesys-df-perl"
669 template "/usr/local/bin/cleanup-tiles" do
670 source "cleanup-tiles.erb"
676 tile_directories = node[:tile][:styles].collect do |_, style|
677 style[:tile_directories].collect { |directory| directory[:name] }
678 end.flatten.sort.uniq
680 tile_directories.each do |directory|
681 label = directory.gsub("/", "-")
683 cron_d "cleanup-tiles#{label}" do
686 command "ionice -c 3 /usr/local/bin/cleanup-tiles #{directory}"
687 mailto "admins@openstreetmap.org"
691 munin_plugin "mod_tile_fresh"
692 munin_plugin "mod_tile_latency"
693 munin_plugin "mod_tile_response"
694 munin_plugin "mod_tile_zoom"
696 munin_plugin "renderd_processed"
697 munin_plugin "renderd_queue"
698 munin_plugin "renderd_queue_time"
699 munin_plugin "renderd_zoom"
700 munin_plugin "renderd_zoom_time"
702 munin_plugin "replication_delay"
704 package "ruby-webrick"
706 prometheus_exporter "modtile" do
710 prometheus_exporter "renderd" do