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
174 ["NotoSansArabicUI-Regular.ttf", "NotoSansArabicUI-Bold.ttf"].each do |font|
175 remote_file "/usr/share/fonts/truetype/noto/#{font}" do
176 action :create_if_missing
177 source "https://github.com/googlei18n/noto-fonts/raw/master/hinted/#{font}"
184 directory "/srv/tile.openstreetmap.org/cgi-bin" do
190 template "/srv/tile.openstreetmap.org/cgi-bin/export" do
195 variables :blocks => blocks, :totp_key => web_passwords["totp_key"]
198 template "/srv/tile.openstreetmap.org/cgi-bin/debug" do
205 template "/etc/cron.hourly/export" do
206 source "export.cron.erb"
212 directory "/srv/tile.openstreetmap.org/data" do
218 package "mapnik-utils"
220 node[:tile][:data].each_value do |data|
222 file = "/srv/tile.openstreetmap.org/data/#{File.basename(url)}"
225 directory = "/srv/tile.openstreetmap.org/data/#{data[:directory]}"
227 directory directory do
233 directory = "/srv/tile.openstreetmap.org/data"
241 command "tar -zxf #{file} -C #{directory}"
245 elsif file =~ /\.tar\.bz2$/
250 command "tar -jxf #{file} -C #{directory}"
254 elsif file =~ /\.zip$/
259 command "unzip -qq -o #{file} -d #{directory}"
265 execute "#{file}_shapeindex" do
267 command "find #{directory} -type f -iname '*.shp' -print0 | xargs -0 --no-run-if-empty shapeindex --shape_files"
270 subscribes :run, "execute[#{file}]", :immediately
276 use_conditional_get true
279 action :create_if_missing
287 notifies :run, "execute[#{file}]", :immediately
288 notifies :restart, "service[renderd]"
292 nodejs_package "carto"
294 systemd_service "update-lowzoom@" do
295 description "Low zoom tile update service for %i layer"
296 conflicts "render-lowzoom.service"
298 exec_start "/bin/bash /usr/local/bin/update-lowzoom-%i"
299 runtime_directory "update-lowzoom-%i"
303 protect_system "full"
305 no_new_privileges true
309 directory "/srv/tile.openstreetmap.org/styles" do
315 node[:tile][:styles].each do |name, details|
316 style_directory = "/srv/tile.openstreetmap.org/styles/#{name}"
317 tile_directory = "/srv/tile.openstreetmap.org/tiles/#{name}"
319 template "/usr/local/bin/update-lowzoom-#{name}" do
320 source "update-lowzoom.erb"
324 variables :style => name
327 service "update-lowzoom@#{name}" do
329 supports :restart => true
332 directory tile_directory do
338 details[:tile_directories].each do |directory|
339 directory directory[:name] do
345 directory[:min_zoom].upto(directory[:max_zoom]) do |zoom|
346 directory "#{directory[:name]}/#{zoom}" do
352 link "#{tile_directory}/#{zoom}" do
353 to "#{directory[:name]}/#{zoom}"
360 file "#{tile_directory}/planet-import-complete" do
361 action :create_if_missing
367 git style_directory do
369 repository details[:repository]
370 revision details[:revision]
375 link "#{style_directory}/data" do
376 to "/srv/tile.openstreetmap.org/data"
381 execute "#{style_directory}/project.mml" do
383 command "carto -a 3.0.0 project.mml > project.xml"
387 subscribes :run, "git[#{style_directory}]"
388 notifies :restart, "service[renderd]", :immediately
389 notifies :restart, "service[update-lowzoom@#{name}]"
393 postgresql_version = node[:tile][:database][:cluster].split("/").first
394 postgis_version = node[:tile][:database][:postgis]
396 package "postgresql-#{postgresql_version}-postgis-#{postgis_version}"
398 postgresql_user "jburgess" do
399 cluster node[:tile][:database][:cluster]
403 postgresql_user "tomh" do
404 cluster node[:tile][:database][:cluster]
408 postgresql_user "tile" do
409 cluster node[:tile][:database][:cluster]
412 postgresql_user "_renderd" do
413 cluster node[:tile][:database][:cluster]
416 postgresql_database "gis" do
417 cluster node[:tile][:database][:cluster]
421 postgresql_extension "postgis" do
422 cluster node[:tile][:database][:cluster]
426 postgresql_extension "hstore" do
427 cluster node[:tile][:database][:cluster]
429 only_if { node[:tile][:database][:hstore] }
432 %w[geography_columns planet_osm_nodes planet_osm_rels planet_osm_ways raster_columns raster_overviews spatial_ref_sys].each do |table|
433 postgresql_table table do
434 cluster node[:tile][:database][:cluster]
437 permissions "tile" => :all
441 %w[geometry_columns planet_osm_line planet_osm_point planet_osm_polygon planet_osm_roads].each do |table|
442 postgresql_table table do
443 cluster node[:tile][:database][:cluster]
446 permissions "tile" => :all, "_renderd" => :select
456 if node[:tile][:database][:external_data_script]
457 execute node[:tile][:database][:external_data_script] do
458 command "#{node[:tile][:database][:external_data_script]} -R _renderd"
459 cwd "/srv/tile.openstreetmap.org"
466 postgresql_munin "gis" do
467 cluster node[:tile][:database][:cluster]
471 directory File.dirname(node[:tile][:database][:node_file]) do
478 file node[:tile][:database][:node_file] do
484 directory "/var/log/tile" do
498 gem_package "apachelogregex"
499 gem_package "file-tail"
500 gem_package "lru_redux"
502 remote_directory "/usr/local/bin" do
512 template "/usr/local/bin/tile-ratelimit" do
513 source "tile-ratelimit.erb"
519 systemd_service "tile-ratelimit" do
520 description "Monitor tile requests and enforce rate limits"
521 after "apache2.service"
524 exec_start "/usr/local/bin/tile-ratelimit"
528 protect_system "full"
530 read_write_paths "/srv/tile.openstreetmap.org/conf"
531 no_new_privileges true
535 service "tile-ratelimit" do
536 action [:enable, :start]
537 subscribes :restart, "file[/usr/local/bin/tile-ratelimit]"
538 subscribes :restart, "systemd_service[tile-ratelimit]"
541 template "/usr/local/bin/expire-tiles" do
542 source "expire-tiles.erb"
548 directory "/var/lib/replicate" do
554 directory "/var/lib/replicate/expire-queue" do
560 template "/usr/local/bin/replicate" do
561 source "replicate.erb"
565 variables :postgresql_version => postgresql_version.to_f
568 systemd_service "expire-tiles" do
569 description "Tile dirtying service"
572 exec_start "/usr/local/bin/expire-tiles"
573 standard_output "null"
576 protect_system "full"
578 no_new_privileges true
581 systemd_path "expire-tiles" do
582 description "Tile dirtying trigger"
583 directory_not_empty "/var/lib/replicate/expire-queue"
586 service "expire-tiles.path" do
587 action [:enable, :start]
588 subscribes :restart, "systemd_path[expire-tiles]"
591 systemd_service "replicate" do
592 description "Rendering database replication service"
593 after "postgresql.service"
594 wants "postgresql.service"
596 exec_start "/usr/local/bin/replicate"
599 protect_system "full"
601 no_new_privileges true
605 service "replicate" do
606 action [:enable, :start]
607 subscribes :restart, "template[/usr/local/bin/replicate]"
608 subscribes :restart, "systemd_service[replicate]"
611 template "/etc/logrotate.d/replicate" do
612 source "replicate.logrotate.erb"
618 template "/usr/local/bin/render-lowzoom" do
619 source "render-lowzoom.erb"
625 systemd_service "render-lowzoom" do
626 description "Render low zoom tiles"
627 condition_path_exists_glob "!/run/update-lowzoom-*"
629 exec_start "/usr/local/bin/render-lowzoom"
633 protect_system "full"
635 no_new_privileges true
638 systemd_timer "render-lowzoom" do
639 description "Render low zoom tiles"
640 on_calendar "Sun *-*~07/1 01:00:00"
643 service "render-lowzoom.timer" do
644 action [:enable, :start]
647 package "liblockfile-simple-perl"
648 package "libfilesys-df-perl"
650 template "/usr/local/bin/cleanup-tiles" do
651 source "cleanup-tiles.erb"
657 tile_directories = node[:tile][:styles].collect do |_, style|
658 style[:tile_directories].collect { |directory| directory[:name] }
659 end.flatten.sort.uniq
661 tile_directories.each do |directory|
662 label = directory.gsub("/", "-")
664 cron_d "cleanup-tiles#{label}" do
667 command "ionice -c 3 /usr/local/bin/cleanup-tiles #{directory}"
668 mailto "admins@openstreetmap.org"
672 munin_plugin "mod_tile_fresh"
673 munin_plugin "mod_tile_latency"
674 munin_plugin "mod_tile_response"
675 munin_plugin "mod_tile_zoom"
677 munin_plugin "renderd_processed"
678 munin_plugin "renderd_queue"
679 munin_plugin "renderd_queue_time"
680 munin_plugin "renderd_zoom"
681 munin_plugin "renderd_zoom_time"
683 munin_plugin "replication_delay"
685 prometheus_exporter "modtile" do
689 prometheus_exporter "renderd" do