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"
278 exec_start "/bin/bash /usr/local/bin/update-lowzoom-%i"
282 protect_system "full"
284 no_new_privileges true
288 directory "/srv/tile.openstreetmap.org/styles" do
294 node[:tile][:styles].each do |name, details|
295 style_directory = "/srv/tile.openstreetmap.org/styles/#{name}"
296 tile_directory = "/srv/tile.openstreetmap.org/tiles/#{name}"
298 template "/usr/local/bin/update-lowzoom-#{name}" do
299 source "update-lowzoom.erb"
303 variables :style => name
306 service "update-lowzoom@#{name}" do
308 supports :restart => true
311 directory tile_directory do
317 details[:tile_directories].each do |directory|
318 directory directory[:name] do
324 directory[:min_zoom].upto(directory[:max_zoom]) do |zoom|
325 directory "#{directory[:name]}/#{zoom}" do
331 link "#{tile_directory}/#{zoom}" do
332 to "#{directory[:name]}/#{zoom}"
339 file "#{tile_directory}/planet-import-complete" do
340 action :create_if_missing
346 git style_directory do
348 repository details[:repository]
349 revision details[:revision]
354 link "#{style_directory}/data" do
355 to "/srv/tile.openstreetmap.org/data"
360 execute "#{style_directory}/project.mml" do
362 command "carto -a 3.0.0 project.mml > project.xml"
366 subscribes :run, "git[#{style_directory}]"
367 notifies :restart, "service[renderd]", :immediately
368 notifies :restart, "service[update-lowzoom@#{name}]"
372 postgresql_version = node[:tile][:database][:cluster].split("/").first
373 postgis_version = node[:tile][:database][:postgis]
375 package "postgresql-#{postgresql_version}-postgis-#{postgis_version}"
377 postgresql_user "jburgess" do
378 cluster node[:tile][:database][:cluster]
382 postgresql_user "tomh" do
383 cluster node[:tile][:database][:cluster]
387 postgresql_user "tile" do
388 cluster node[:tile][:database][:cluster]
391 postgresql_user "www-data" do
392 cluster node[:tile][:database][:cluster]
395 postgresql_database "gis" do
396 cluster node[:tile][:database][:cluster]
400 postgresql_extension "postgis" do
401 cluster node[:tile][:database][:cluster]
405 postgresql_extension "hstore" do
406 cluster node[:tile][:database][:cluster]
408 only_if { node[:tile][:database][:hstore] }
411 %w[geography_columns planet_osm_nodes planet_osm_rels planet_osm_ways raster_columns raster_overviews spatial_ref_sys].each do |table|
412 postgresql_table table do
413 cluster node[:tile][:database][:cluster]
416 permissions "tile" => :all
420 %w[geometry_columns planet_osm_line planet_osm_point planet_osm_polygon planet_osm_roads].each do |table|
421 postgresql_table table do
422 cluster node[:tile][:database][:cluster]
425 permissions "tile" => :all, "www-data" => :select
429 postgresql_munin "gis" do
430 cluster node[:tile][:database][:cluster]
434 directory File.dirname(node[:tile][:database][:node_file]) do
441 file node[:tile][:database][:node_file] do
447 directory "/var/log/tile" do
461 remote_directory "/usr/local/bin" do
471 template "/usr/local/bin/expire-tiles" do
472 source "expire-tiles.erb"
478 directory "/var/lib/replicate" do
484 directory "/var/lib/replicate/expire-queue" do
490 template "/usr/local/bin/replicate" do
491 source "replicate.erb"
495 variables :postgresql_version => postgresql_version.to_f
498 systemd_service "expire-tiles" do
499 description "Tile dirtying service"
502 exec_start "/usr/local/bin/expire-tiles"
503 standard_output "null"
506 protect_system "full"
508 no_new_privileges true
511 systemd_path "expire-tiles" do
512 description "Tile dirtying trigger"
513 directory_not_empty "/var/lib/replicate/expire-queue"
516 service "expire-tiles.path" do
517 action [:enable, :start]
518 subscribes :restart, "systemd_path[expire-tiles]"
521 systemd_service "replicate" do
522 description "Rendering database replication service"
523 after "postgresql.service"
524 wants "postgresql.service"
526 exec_start "/usr/local/bin/replicate"
529 protect_system "full"
531 no_new_privileges true
535 service "replicate" do
536 action [:enable, :start]
537 subscribes :restart, "template[/usr/local/bin/replicate]"
538 subscribes :restart, "systemd_service[replicate]"
541 template "/etc/logrotate.d/replicate" do
542 source "replicate.logrotate.erb"
548 template "/usr/local/bin/render-lowzoom" do
549 source "render-lowzoom.erb"
555 systemd_service "render-lowzoom" do
556 description "Render low zoom tiles"
558 exec_start "/usr/local/bin/render-lowzoom"
562 protect_system "full"
564 no_new_privileges true
567 systemd_timer "render-lowzoom" do
568 description "Render low zoom tiles"
569 on_calendar "Sun *-*~07/1 01:00:00"
572 service "render-lowzoom.timer" do
573 action [:enable, :start]
576 package "liblockfile-simple-perl"
577 package "libfilesys-df-perl"
579 template "/usr/local/bin/cleanup-tiles" do
580 source "cleanup-tiles.erb"
586 tile_directories = node[:tile][:styles].collect do |_, style|
587 style[:tile_directories].collect { |directory| directory[:name] }
588 end.flatten.sort.uniq
590 tile_directories.each do |directory|
591 label = directory.gsub("/", "-")
593 cron_d "cleanup-tiles#{label}" do
596 command "ionice -c 3 /usr/local/bin/cleanup-tiles #{directory}"
597 mailto "admins@openstreetmap.org"
601 munin_plugin "mod_tile_fresh"
602 munin_plugin "mod_tile_latency"
603 munin_plugin "mod_tile_response"
604 munin_plugin "mod_tile_zoom"
606 munin_plugin "renderd_processed"
607 munin_plugin "renderd_queue"
608 munin_plugin "renderd_queue_time"
609 munin_plugin "renderd_zoom"
610 munin_plugin "renderd_zoom_time"
612 munin_plugin "replication_delay"
614 prometheus_exporter "modtile" do
618 prometheus_exporter "renderd" do