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 ssl_certificate node[:fqdn] do
45 domains [node[:fqdn], "tile.openstreetmap.org", "render.openstreetmap.org"]
46 notifies :reload, "service[apache2]"
49 remote_file "#{Chef::Config[:file_cache_path]}/fastly-ip-list.json" do
50 source "https://api.fastly.com/public-ip-list"
55 tilecaches = search(:node, "roles:tilecache").sort_by { |n| n[:hostname] }
56 fastlyips = JSON.parse(IO.read("#{Chef::Config[:file_cache_path]}/fastly-ip-list.json"))
58 apache_site "default" do
62 apache_site "tile.openstreetmap.org" do
64 variables :caches => tilecaches, :fastly => fastlyips["addresses"]
67 template "/etc/logrotate.d/apache2" do
68 source "logrotate.apache.erb"
74 directory "/srv/tile.openstreetmap.org" do
82 systemd_service "renderd" do
83 description "Mapnik rendering daemon"
84 after "postgresql.service"
85 wants "postgresql.service"
87 exec_start "/usr/bin/renderd -f"
88 runtime_directory "renderd"
97 no_new_privileges true
102 action [:enable, :start]
103 subscribes :restart, "systemd_service[renderd]"
106 directory "/srv/tile.openstreetmap.org/tiles" do
112 template "/etc/renderd.conf" do
113 source "renderd.conf.erb"
117 notifies :reload, "service[apache2]"
118 notifies :restart, "service[renderd]"
121 remote_directory "/srv/tile.openstreetmap.org/html" do
131 template "/srv/tile.openstreetmap.org/html/index.html" do
132 source "index.html.erb"
144 python_package "pyotp" do
156 ["NotoSansArabicUI-Regular.ttf", "NotoSansArabicUI-Bold.ttf"].each do |font|
157 remote_file "/usr/share/fonts/truetype/noto/#{font}" do
158 action :create_if_missing
159 source "https://github.com/googlei18n/noto-fonts/raw/master/hinted/#{font}"
166 directory "/srv/tile.openstreetmap.org/cgi-bin" do
172 template "/srv/tile.openstreetmap.org/cgi-bin/export" do
177 variables :blocks => blocks, :totp_key => web_passwords["totp_key"]
180 template "/srv/tile.openstreetmap.org/cgi-bin/debug" do
187 template "/etc/cron.hourly/export" do
188 source "export.cron.erb"
194 directory "/srv/tile.openstreetmap.org/data" do
200 package "mapnik-utils"
202 node[:tile][:data].each_value do |data|
204 file = "/srv/tile.openstreetmap.org/data/#{File.basename(url)}"
207 directory = "/srv/tile.openstreetmap.org/data/#{data[:directory]}"
209 directory directory do
215 directory = "/srv/tile.openstreetmap.org/data"
223 command "tar -zxf #{file} -C #{directory}"
227 elsif file =~ /\.tar\.bz2$/
232 command "tar -jxf #{file} -C #{directory}"
236 elsif file =~ /\.zip$/
241 command "unzip -qq -o #{file} -d #{directory}"
247 execute "#{file}_shapeindex" do
249 command "find #{directory} -type f -iname '*.shp' -print0 | xargs -0 --no-run-if-empty shapeindex --shape_files"
252 subscribes :run, "execute[#{file}]", :immediately
258 use_conditional_get true
261 action :create_if_missing
269 notifies :run, "execute[#{file}]", :immediately
270 notifies :restart, "service[renderd]"
274 nodejs_package "carto"
276 systemd_service "update-lowzoom@" do
277 description "Low zoom tile update service for %i layer"
278 conflicts "render-lowzoom.service"
280 exec_start "/bin/bash /usr/local/bin/update-lowzoom-%i"
281 runtime_directory "update-lowzoom-%i"
285 protect_system "full"
287 no_new_privileges true
291 directory "/srv/tile.openstreetmap.org/styles" do
297 node[:tile][:styles].each do |name, details|
298 style_directory = "/srv/tile.openstreetmap.org/styles/#{name}"
299 tile_directory = "/srv/tile.openstreetmap.org/tiles/#{name}"
301 template "/usr/local/bin/update-lowzoom-#{name}" do
302 source "update-lowzoom.erb"
306 variables :style => name
309 service "update-lowzoom@#{name}" do
311 supports :restart => true
314 directory tile_directory do
320 details[:tile_directories].each do |directory|
321 directory directory[:name] do
327 directory[:min_zoom].upto(directory[:max_zoom]) do |zoom|
328 directory "#{directory[:name]}/#{zoom}" do
334 link "#{tile_directory}/#{zoom}" do
335 to "#{directory[:name]}/#{zoom}"
342 file "#{tile_directory}/planet-import-complete" do
343 action :create_if_missing
349 git style_directory do
351 repository details[:repository]
352 revision details[:revision]
357 link "#{style_directory}/data" do
358 to "/srv/tile.openstreetmap.org/data"
363 execute "#{style_directory}/project.mml" do
365 command "carto -a 3.0.0 project.mml > project.xml"
369 subscribes :run, "git[#{style_directory}]"
370 notifies :restart, "service[renderd]", :immediately
371 notifies :restart, "service[update-lowzoom@#{name}]"
375 postgresql_version = node[:tile][:database][:cluster].split("/").first
376 postgis_version = node[:tile][:database][:postgis]
378 package "postgresql-#{postgresql_version}-postgis-#{postgis_version}"
380 postgresql_user "jburgess" do
381 cluster node[:tile][:database][:cluster]
385 postgresql_user "tomh" do
386 cluster node[:tile][:database][:cluster]
390 postgresql_user "tile" do
391 cluster node[:tile][:database][:cluster]
394 postgresql_user "www-data" do
395 cluster node[:tile][:database][:cluster]
398 postgresql_database "gis" do
399 cluster node[:tile][:database][:cluster]
403 postgresql_extension "postgis" do
404 cluster node[:tile][:database][:cluster]
408 postgresql_extension "hstore" do
409 cluster node[:tile][:database][:cluster]
411 only_if { node[:tile][:database][:hstore] }
414 %w[geography_columns planet_osm_nodes planet_osm_rels planet_osm_ways raster_columns raster_overviews spatial_ref_sys].each do |table|
415 postgresql_table table do
416 cluster node[:tile][:database][:cluster]
419 permissions "tile" => :all
423 %w[geometry_columns planet_osm_line planet_osm_point planet_osm_polygon planet_osm_roads].each do |table|
424 postgresql_table table do
425 cluster node[:tile][:database][:cluster]
428 permissions "tile" => :all, "www-data" => :select
438 if node[:tile][:database][:external_data_script]
439 execute node[:tile][:database][:external_data_script] do
440 command "#{node[:tile][:database][:external_data_script]} -R www-data"
441 cwd "/srv/tile.openstreetmap.org"
447 postgresql_munin "gis" do
448 cluster node[:tile][:database][:cluster]
452 directory File.dirname(node[:tile][:database][:node_file]) do
459 file node[:tile][:database][:node_file] do
465 directory "/var/log/tile" do
479 remote_directory "/usr/local/bin" do
489 template "/usr/local/bin/expire-tiles" do
490 source "expire-tiles.erb"
496 directory "/var/lib/replicate" do
502 directory "/var/lib/replicate/expire-queue" do
508 template "/usr/local/bin/replicate" do
509 source "replicate.erb"
513 variables :postgresql_version => postgresql_version.to_f
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 systemd_service "render-lowzoom" do
574 description "Render low zoom tiles"
575 condition_path_exists_glob "!/run/update-lowzoom-*"
577 exec_start "/usr/local/bin/render-lowzoom"
581 protect_system "full"
583 no_new_privileges true
586 systemd_timer "render-lowzoom" do
587 description "Render low zoom tiles"
588 on_calendar "Sun *-*~07/1 01:00:00"
591 service "render-lowzoom.timer" do
592 action [:enable, :start]
595 package "liblockfile-simple-perl"
596 package "libfilesys-df-perl"
598 template "/usr/local/bin/cleanup-tiles" do
599 source "cleanup-tiles.erb"
605 tile_directories = node[:tile][:styles].collect do |_, style|
606 style[:tile_directories].collect { |directory| directory[:name] }
607 end.flatten.sort.uniq
609 tile_directories.each do |directory|
610 label = directory.gsub("/", "-")
612 cron_d "cleanup-tiles#{label}" do
615 command "ionice -c 3 /usr/local/bin/cleanup-tiles #{directory}"
616 mailto "admins@openstreetmap.org"
620 munin_plugin "mod_tile_fresh"
621 munin_plugin "mod_tile_latency"
622 munin_plugin "mod_tile_response"
623 munin_plugin "mod_tile_zoom"
625 munin_plugin "renderd_processed"
626 munin_plugin "renderd_queue"
627 munin_plugin "renderd_queue_time"
628 munin_plugin "renderd_zoom"
629 munin_plugin "renderd_zoom_time"
631 munin_plugin "replication_delay"
633 prometheus_exporter "modtile" do
637 prometheus_exporter "renderd" do