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"
96 no_new_privileges true
101 action [:enable, :start]
102 subscribes :restart, "systemd_service[renderd]"
105 directory "/srv/tile.openstreetmap.org/tiles" do
111 template "/etc/renderd.conf" do
112 source "renderd.conf.erb"
116 notifies :reload, "service[apache2]"
117 notifies :restart, "service[renderd]"
120 remote_directory "/srv/tile.openstreetmap.org/html" do
130 template "/srv/tile.openstreetmap.org/html/index.html" do
131 source "index.html.erb"
143 python_package "pyotp" do
155 ["NotoSansArabicUI-Regular.ttf", "NotoSansArabicUI-Bold.ttf"].each do |font|
156 remote_file "/usr/share/fonts/truetype/noto/#{font}" do
157 action :create_if_missing
158 source "https://github.com/googlei18n/noto-fonts/raw/master/hinted/#{font}"
165 directory "/srv/tile.openstreetmap.org/cgi-bin" do
171 template "/srv/tile.openstreetmap.org/cgi-bin/export" do
176 variables :blocks => blocks, :totp_key => web_passwords["totp_key"]
179 template "/srv/tile.openstreetmap.org/cgi-bin/debug" do
186 template "/etc/cron.hourly/export" do
187 source "export.cron.erb"
193 directory "/srv/tile.openstreetmap.org/data" do
199 package "mapnik-utils"
201 node[:tile][:data].each_value do |data|
203 file = "/srv/tile.openstreetmap.org/data/#{File.basename(url)}"
206 directory = "/srv/tile.openstreetmap.org/data/#{data[:directory]}"
208 directory directory do
214 directory = "/srv/tile.openstreetmap.org/data"
222 command "tar -zxf #{file} -C #{directory}"
226 elsif file =~ /\.tar\.bz2$/
231 command "tar -jxf #{file} -C #{directory}"
235 elsif file =~ /\.zip$/
240 command "unzip -qq -o #{file} -d #{directory}"
246 execute "#{file}_shapeindex" do
248 command "find #{directory} -type f -iname '*.shp' -print0 | xargs -0 --no-run-if-empty shapeindex --shape_files"
251 subscribes :run, "execute[#{file}]", :immediately
257 use_conditional_get true
260 action :create_if_missing
268 notifies :run, "execute[#{file}]", :immediately
269 notifies :restart, "service[renderd]"
273 nodejs_package "carto"
275 systemd_service "update-lowzoom@" do
276 description "Low zoom tile update service for %i layer"
277 conflicts "render-lowzoom.service"
279 exec_start "/bin/bash /usr/local/bin/update-lowzoom-%i"
280 runtime_directory "update-lowzoom-%i"
284 protect_system "full"
286 no_new_privileges true
290 directory "/srv/tile.openstreetmap.org/styles" do
296 node[:tile][:styles].each do |name, details|
297 style_directory = "/srv/tile.openstreetmap.org/styles/#{name}"
298 tile_directory = "/srv/tile.openstreetmap.org/tiles/#{name}"
300 template "/usr/local/bin/update-lowzoom-#{name}" do
301 source "update-lowzoom.erb"
305 variables :style => name
308 service "update-lowzoom@#{name}" do
310 supports :restart => true
313 directory tile_directory do
319 details[:tile_directories].each do |directory|
320 directory directory[:name] do
326 directory[:min_zoom].upto(directory[:max_zoom]) do |zoom|
327 directory "#{directory[:name]}/#{zoom}" do
333 link "#{tile_directory}/#{zoom}" do
334 to "#{directory[:name]}/#{zoom}"
341 file "#{tile_directory}/planet-import-complete" do
342 action :create_if_missing
348 git style_directory do
350 repository details[:repository]
351 revision details[:revision]
356 link "#{style_directory}/data" do
357 to "/srv/tile.openstreetmap.org/data"
362 execute "#{style_directory}/project.mml" do
364 command "carto -a 3.0.0 project.mml > project.xml"
368 subscribes :run, "git[#{style_directory}]"
369 notifies :restart, "service[renderd]", :immediately
370 notifies :restart, "service[update-lowzoom@#{name}]"
374 postgresql_version = node[:tile][:database][:cluster].split("/").first
375 postgis_version = node[:tile][:database][:postgis]
377 package "postgresql-#{postgresql_version}-postgis-#{postgis_version}"
379 postgresql_user "jburgess" do
380 cluster node[:tile][:database][:cluster]
384 postgresql_user "tomh" do
385 cluster node[:tile][:database][:cluster]
389 postgresql_user "tile" do
390 cluster node[:tile][:database][:cluster]
393 postgresql_user "www-data" do
394 cluster node[:tile][:database][:cluster]
397 postgresql_database "gis" do
398 cluster node[:tile][:database][:cluster]
402 postgresql_extension "postgis" do
403 cluster node[:tile][:database][:cluster]
407 postgresql_extension "hstore" do
408 cluster node[:tile][:database][:cluster]
410 only_if { node[:tile][:database][:hstore] }
413 %w[geography_columns planet_osm_nodes planet_osm_rels planet_osm_ways raster_columns raster_overviews spatial_ref_sys].each do |table|
414 postgresql_table table do
415 cluster node[:tile][:database][:cluster]
418 permissions "tile" => :all
422 %w[geometry_columns planet_osm_line planet_osm_point planet_osm_polygon planet_osm_roads].each do |table|
423 postgresql_table table do
424 cluster node[:tile][:database][:cluster]
427 permissions "tile" => :all, "www-data" => :select
437 if node[:tile][:database][:external_data_script]
438 execute node[:tile][:database][:external_data_script] do
439 command node[:tile][:database][:external_data_script]
440 cwd "/srv/tile.openstreetmap.org"
445 Array(node[:tile][:database][:external_data_tables]).each do |table|
446 postgresql_table table do
447 cluster node[:tile][:database][:cluster]
450 permissions "tile" => :all, "www-data" => :select
455 postgresql_munin "gis" do
456 cluster node[:tile][:database][:cluster]
460 directory File.dirname(node[:tile][:database][:node_file]) do
467 file node[:tile][:database][:node_file] do
473 directory "/var/log/tile" do
487 remote_directory "/usr/local/bin" do
497 template "/usr/local/bin/expire-tiles" do
498 source "expire-tiles.erb"
504 directory "/var/lib/replicate" do
510 directory "/var/lib/replicate/expire-queue" do
516 template "/usr/local/bin/replicate" do
517 source "replicate.erb"
521 variables :postgresql_version => postgresql_version.to_f
524 systemd_service "expire-tiles" do
525 description "Tile dirtying service"
528 exec_start "/usr/local/bin/expire-tiles"
529 standard_output "null"
532 protect_system "full"
534 no_new_privileges true
537 systemd_path "expire-tiles" do
538 description "Tile dirtying trigger"
539 directory_not_empty "/var/lib/replicate/expire-queue"
542 service "expire-tiles.path" do
543 action [:enable, :start]
544 subscribes :restart, "systemd_path[expire-tiles]"
547 systemd_service "replicate" do
548 description "Rendering database replication service"
549 after "postgresql.service"
550 wants "postgresql.service"
552 exec_start "/usr/local/bin/replicate"
555 protect_system "full"
557 no_new_privileges true
561 service "replicate" do
562 action [:enable, :start]
563 subscribes :restart, "template[/usr/local/bin/replicate]"
564 subscribes :restart, "systemd_service[replicate]"
567 template "/etc/logrotate.d/replicate" do
568 source "replicate.logrotate.erb"
574 template "/usr/local/bin/render-lowzoom" do
575 source "render-lowzoom.erb"
581 systemd_service "render-lowzoom" do
582 description "Render low zoom tiles"
583 condition_path_exists_glob "!/run/update-lowzoom-*"
585 exec_start "/usr/local/bin/render-lowzoom"
589 protect_system "full"
591 no_new_privileges true
594 systemd_timer "render-lowzoom" do
595 description "Render low zoom tiles"
596 on_calendar "Sun *-*~07/1 01:00:00"
599 service "render-lowzoom.timer" do
600 action [:enable, :start]
603 package "liblockfile-simple-perl"
604 package "libfilesys-df-perl"
606 template "/usr/local/bin/cleanup-tiles" do
607 source "cleanup-tiles.erb"
613 tile_directories = node[:tile][:styles].collect do |_, style|
614 style[:tile_directories].collect { |directory| directory[:name] }
615 end.flatten.sort.uniq
617 tile_directories.each do |directory|
618 label = directory.gsub("/", "-")
620 cron_d "cleanup-tiles#{label}" do
623 command "ionice -c 3 /usr/local/bin/cleanup-tiles #{directory}"
624 mailto "admins@openstreetmap.org"
628 munin_plugin "mod_tile_fresh"
629 munin_plugin "mod_tile_latency"
630 munin_plugin "mod_tile_response"
631 munin_plugin "mod_tile_zoom"
633 munin_plugin "renderd_processed"
634 munin_plugin "renderd_queue"
635 munin_plugin "renderd_queue_time"
636 munin_plugin "renderd_zoom"
637 munin_plugin "renderd_zoom_time"
639 munin_plugin "replication_delay"
641 prometheus_exporter "modtile" do
645 prometheus_exporter "renderd" do