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 tilecaches = search(:node, "roles:tilecache").sort_by { |n| n[:hostname] }
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 :caches => tilecaches, :fastly => fastlyips["addresses"]
75 template "/etc/logrotate.d/apache2" do
76 source "logrotate.apache.erb"
82 directory "/srv/tile.openstreetmap.org" do
90 systemd_service "renderd" do
91 description "Mapnik rendering daemon"
92 after "postgresql.service"
93 wants "postgresql.service"
95 exec_start "/usr/bin/renderd -f"
96 runtime_directory "renderd"
102 protect_system "full"
104 no_new_privileges true
109 action [:enable, :start]
110 subscribes :restart, "systemd_service[renderd]"
113 directory "/srv/tile.openstreetmap.org/tiles" do
119 template "/etc/renderd.conf" do
120 source "renderd.conf.erb"
124 notifies :reload, "service[apache2]"
125 notifies :restart, "service[renderd]"
128 remote_directory "/srv/tile.openstreetmap.org/html" do
138 template "/srv/tile.openstreetmap.org/html/index.html" do
139 source "index.html.erb"
151 python_package "pyotp" do
163 ["NotoSansArabicUI-Regular.ttf", "NotoSansArabicUI-Bold.ttf"].each do |font|
164 remote_file "/usr/share/fonts/truetype/noto/#{font}" do
165 action :create_if_missing
166 source "https://github.com/googlei18n/noto-fonts/raw/master/hinted/#{font}"
173 directory "/srv/tile.openstreetmap.org/cgi-bin" do
179 template "/srv/tile.openstreetmap.org/cgi-bin/export" do
184 variables :blocks => blocks, :totp_key => web_passwords["totp_key"]
187 template "/srv/tile.openstreetmap.org/cgi-bin/debug" do
194 template "/etc/cron.hourly/export" do
195 source "export.cron.erb"
201 directory "/srv/tile.openstreetmap.org/data" do
207 package "mapnik-utils"
209 node[:tile][:data].each_value do |data|
211 file = "/srv/tile.openstreetmap.org/data/#{File.basename(url)}"
214 directory = "/srv/tile.openstreetmap.org/data/#{data[:directory]}"
216 directory directory do
222 directory = "/srv/tile.openstreetmap.org/data"
230 command "tar -zxf #{file} -C #{directory}"
234 elsif file =~ /\.tar\.bz2$/
239 command "tar -jxf #{file} -C #{directory}"
243 elsif file =~ /\.zip$/
248 command "unzip -qq -o #{file} -d #{directory}"
254 execute "#{file}_shapeindex" do
256 command "find #{directory} -type f -iname '*.shp' -print0 | xargs -0 --no-run-if-empty shapeindex --shape_files"
259 subscribes :run, "execute[#{file}]", :immediately
265 use_conditional_get true
268 action :create_if_missing
276 notifies :run, "execute[#{file}]", :immediately
277 notifies :restart, "service[renderd]"
281 nodejs_package "carto"
283 systemd_service "update-lowzoom@" do
284 description "Low zoom tile update service for %i layer"
285 conflicts "render-lowzoom.service"
287 exec_start "/bin/bash /usr/local/bin/update-lowzoom-%i"
288 runtime_directory "update-lowzoom-%i"
292 protect_system "full"
294 no_new_privileges true
298 directory "/srv/tile.openstreetmap.org/styles" do
304 node[:tile][:styles].each do |name, details|
305 style_directory = "/srv/tile.openstreetmap.org/styles/#{name}"
306 tile_directory = "/srv/tile.openstreetmap.org/tiles/#{name}"
308 template "/usr/local/bin/update-lowzoom-#{name}" do
309 source "update-lowzoom.erb"
313 variables :style => name
316 service "update-lowzoom@#{name}" do
318 supports :restart => true
321 directory tile_directory do
327 details[:tile_directories].each do |directory|
328 directory directory[:name] do
334 directory[:min_zoom].upto(directory[:max_zoom]) do |zoom|
335 directory "#{directory[:name]}/#{zoom}" do
341 link "#{tile_directory}/#{zoom}" do
342 to "#{directory[:name]}/#{zoom}"
349 file "#{tile_directory}/planet-import-complete" do
350 action :create_if_missing
356 git style_directory do
358 repository details[:repository]
359 revision details[:revision]
364 link "#{style_directory}/data" do
365 to "/srv/tile.openstreetmap.org/data"
370 execute "#{style_directory}/project.mml" do
372 command "carto -a 3.0.0 project.mml > project.xml"
376 subscribes :run, "git[#{style_directory}]"
377 notifies :restart, "service[renderd]", :immediately
378 notifies :restart, "service[update-lowzoom@#{name}]"
382 postgresql_version = node[:tile][:database][:cluster].split("/").first
383 postgis_version = node[:tile][:database][:postgis]
385 package "postgresql-#{postgresql_version}-postgis-#{postgis_version}"
387 postgresql_user "jburgess" do
388 cluster node[:tile][:database][:cluster]
392 postgresql_user "tomh" do
393 cluster node[:tile][:database][:cluster]
397 postgresql_user "tile" do
398 cluster node[:tile][:database][:cluster]
401 postgresql_user "www-data" do
402 cluster node[:tile][:database][:cluster]
405 postgresql_database "gis" do
406 cluster node[:tile][:database][:cluster]
410 postgresql_extension "postgis" do
411 cluster node[:tile][:database][:cluster]
415 postgresql_extension "hstore" do
416 cluster node[:tile][:database][:cluster]
418 only_if { node[:tile][:database][:hstore] }
421 %w[geography_columns planet_osm_nodes planet_osm_rels planet_osm_ways raster_columns raster_overviews spatial_ref_sys].each do |table|
422 postgresql_table table do
423 cluster node[:tile][:database][:cluster]
426 permissions "tile" => :all
430 %w[geometry_columns planet_osm_line planet_osm_point planet_osm_polygon planet_osm_roads].each do |table|
431 postgresql_table table do
432 cluster node[:tile][:database][:cluster]
435 permissions "tile" => :all, "www-data" => :select
445 if node[:tile][:database][:external_data_script]
446 execute node[:tile][:database][:external_data_script] do
447 command "#{node[:tile][:database][:external_data_script]} -R www-data"
448 cwd "/srv/tile.openstreetmap.org"
454 postgresql_munin "gis" do
455 cluster node[:tile][:database][:cluster]
459 directory File.dirname(node[:tile][:database][:node_file]) do
466 file node[:tile][:database][:node_file] do
472 directory "/var/log/tile" do
486 remote_directory "/usr/local/bin" do
496 template "/usr/local/bin/expire-tiles" do
497 source "expire-tiles.erb"
503 directory "/var/lib/replicate" do
509 directory "/var/lib/replicate/expire-queue" do
515 template "/usr/local/bin/replicate" do
516 source "replicate.erb"
520 variables :postgresql_version => postgresql_version.to_f
523 systemd_service "expire-tiles" do
524 description "Tile dirtying service"
527 exec_start "/usr/local/bin/expire-tiles"
528 standard_output "null"
531 protect_system "full"
533 no_new_privileges true
536 systemd_path "expire-tiles" do
537 description "Tile dirtying trigger"
538 directory_not_empty "/var/lib/replicate/expire-queue"
541 service "expire-tiles.path" do
542 action [:enable, :start]
543 subscribes :restart, "systemd_path[expire-tiles]"
546 systemd_service "replicate" do
547 description "Rendering database replication service"
548 after "postgresql.service"
549 wants "postgresql.service"
551 exec_start "/usr/local/bin/replicate"
554 protect_system "full"
556 no_new_privileges true
560 service "replicate" do
561 action [:enable, :start]
562 subscribes :restart, "template[/usr/local/bin/replicate]"
563 subscribes :restart, "systemd_service[replicate]"
566 template "/etc/logrotate.d/replicate" do
567 source "replicate.logrotate.erb"
573 template "/usr/local/bin/render-lowzoom" do
574 source "render-lowzoom.erb"
580 systemd_service "render-lowzoom" do
581 description "Render low zoom tiles"
582 condition_path_exists_glob "!/run/update-lowzoom-*"
584 exec_start "/usr/local/bin/render-lowzoom"
588 protect_system "full"
590 no_new_privileges true
593 systemd_timer "render-lowzoom" do
594 description "Render low zoom tiles"
595 on_calendar "Sun *-*~07/1 01:00:00"
598 service "render-lowzoom.timer" do
599 action [:enable, :start]
602 package "liblockfile-simple-perl"
603 package "libfilesys-df-perl"
605 template "/usr/local/bin/cleanup-tiles" do
606 source "cleanup-tiles.erb"
612 tile_directories = node[:tile][:styles].collect do |_, style|
613 style[:tile_directories].collect { |directory| directory[:name] }
614 end.flatten.sort.uniq
616 tile_directories.each do |directory|
617 label = directory.gsub("/", "-")
619 cron_d "cleanup-tiles#{label}" do
622 command "ionice -c 3 /usr/local/bin/cleanup-tiles #{directory}"
623 mailto "admins@openstreetmap.org"
627 munin_plugin "mod_tile_fresh"
628 munin_plugin "mod_tile_latency"
629 munin_plugin "mod_tile_response"
630 munin_plugin "mod_tile_zoom"
632 munin_plugin "renderd_processed"
633 munin_plugin "renderd_queue"
634 munin_plugin "renderd_queue_time"
635 munin_plugin "renderd_zoom"
636 munin_plugin "renderd_zoom_time"
638 munin_plugin "replication_delay"
640 prometheus_exporter "modtile" do
644 prometheus_exporter "renderd" do