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]} -R www-data"
440 cwd "/srv/tile.openstreetmap.org"
446 postgresql_munin "gis" do
447 cluster node[:tile][:database][:cluster]
451 directory File.dirname(node[:tile][:database][:node_file]) do
458 file node[:tile][:database][:node_file] do
464 directory "/var/log/tile" do
478 remote_directory "/usr/local/bin" do
488 template "/usr/local/bin/expire-tiles" do
489 source "expire-tiles.erb"
495 directory "/var/lib/replicate" do
501 directory "/var/lib/replicate/expire-queue" do
507 template "/usr/local/bin/replicate" do
508 source "replicate.erb"
512 variables :postgresql_version => postgresql_version.to_f
515 systemd_service "expire-tiles" do
516 description "Tile dirtying service"
519 exec_start "/usr/local/bin/expire-tiles"
520 standard_output "null"
523 protect_system "full"
525 no_new_privileges true
528 systemd_path "expire-tiles" do
529 description "Tile dirtying trigger"
530 directory_not_empty "/var/lib/replicate/expire-queue"
533 service "expire-tiles.path" do
534 action [:enable, :start]
535 subscribes :restart, "systemd_path[expire-tiles]"
538 systemd_service "replicate" do
539 description "Rendering database replication service"
540 after "postgresql.service"
541 wants "postgresql.service"
543 exec_start "/usr/local/bin/replicate"
546 protect_system "full"
548 no_new_privileges true
552 service "replicate" do
553 action [:enable, :start]
554 subscribes :restart, "template[/usr/local/bin/replicate]"
555 subscribes :restart, "systemd_service[replicate]"
558 template "/etc/logrotate.d/replicate" do
559 source "replicate.logrotate.erb"
565 template "/usr/local/bin/render-lowzoom" do
566 source "render-lowzoom.erb"
572 systemd_service "render-lowzoom" do
573 description "Render low zoom tiles"
574 condition_path_exists_glob "!/run/update-lowzoom-*"
576 exec_start "/usr/local/bin/render-lowzoom"
580 protect_system "full"
582 no_new_privileges true
585 systemd_timer "render-lowzoom" do
586 description "Render low zoom tiles"
587 on_calendar "Sun *-*~07/1 01:00:00"
590 service "render-lowzoom.timer" do
591 action [:enable, :start]
594 package "liblockfile-simple-perl"
595 package "libfilesys-df-perl"
597 template "/usr/local/bin/cleanup-tiles" do
598 source "cleanup-tiles.erb"
604 tile_directories = node[:tile][:styles].collect do |_, style|
605 style[:tile_directories].collect { |directory| directory[:name] }
606 end.flatten.sort.uniq
608 tile_directories.each do |directory|
609 label = directory.gsub("/", "-")
611 cron_d "cleanup-tiles#{label}" do
614 command "ionice -c 3 /usr/local/bin/cleanup-tiles #{directory}"
615 mailto "admins@openstreetmap.org"
619 munin_plugin "mod_tile_fresh"
620 munin_plugin "mod_tile_latency"
621 munin_plugin "mod_tile_response"
622 munin_plugin "mod_tile_zoom"
624 munin_plugin "renderd_processed"
625 munin_plugin "renderd_queue"
626 munin_plugin "renderd_queue_time"
627 munin_plugin "renderd_zoom"
628 munin_plugin "renderd_zoom_time"
630 munin_plugin "replication_delay"
632 prometheus_exporter "modtile" do
636 prometheus_exporter "renderd" do