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"
54 tilecaches = search(:node, "roles:tilecache").sort_by { |n| n[:hostname] }
55 fastlyips = JSON.parse(IO.read("#{Chef::Config[:file_cache_path]}/fastly-ip-list.json"))
57 apache_site "default" do
61 apache_site "tile.openstreetmap.org" do
63 variables :caches => tilecaches, :fastly => fastlyips["addresses"]
66 template "/etc/logrotate.d/apache2" do
67 source "logrotate.apache.erb"
73 directory "/srv/tile.openstreetmap.org" do
81 systemd_service "renderd" do
82 description "Mapnik rendering daemon"
83 after "postgresql.service"
84 wants "postgresql.service"
86 exec_start "/usr/bin/renderd -f"
87 runtime_directory "renderd"
94 no_new_privileges true
99 action [:enable, :start]
100 subscribes :restart, "systemd_service[renderd]"
103 directory "/srv/tile.openstreetmap.org/tiles" do
109 template "/etc/renderd.conf" do
110 source "renderd.conf.erb"
114 notifies :reload, "service[apache2]"
115 notifies :restart, "service[renderd]"
118 remote_directory "/srv/tile.openstreetmap.org/html" do
128 template "/srv/tile.openstreetmap.org/html/index.html" do
129 source "index.html.erb"
141 python_package "pyotp" do
153 ["NotoSansArabicUI-Regular.ttf", "NotoSansArabicUI-Bold.ttf"].each do |font|
154 remote_file "/usr/share/fonts/truetype/noto/#{font}" do
155 action :create_if_missing
156 source "https://github.com/googlei18n/noto-fonts/raw/master/hinted/#{font}"
163 directory "/srv/tile.openstreetmap.org/cgi-bin" do
169 template "/srv/tile.openstreetmap.org/cgi-bin/export" do
174 variables :blocks => blocks, :totp_key => web_passwords["totp_key"]
177 template "/srv/tile.openstreetmap.org/cgi-bin/debug" do
184 template "/etc/cron.hourly/export" do
185 source "export.cron.erb"
191 directory "/srv/tile.openstreetmap.org/data" do
197 package "mapnik-utils"
199 node[:tile][:data].each_value do |data|
201 file = "/srv/tile.openstreetmap.org/data/#{File.basename(url)}"
204 directory = "/srv/tile.openstreetmap.org/data/#{data[:directory]}"
206 directory directory do
212 directory = "/srv/tile.openstreetmap.org/data"
220 command "tar -zxf #{file} -C #{directory}"
224 elsif file =~ /\.tar\.bz2$/
229 command "tar -jxf #{file} -C #{directory}"
233 elsif file =~ /\.zip$/
238 command "unzip -qq -o #{file} -d #{directory}"
244 execute "#{file}_shapeindex" do
246 command "find #{directory} -type f -iname '*.shp' -print0 | xargs -0 --no-run-if-empty shapeindex --shape_files"
249 subscribes :run, "execute[#{file}]", :immediately
255 use_conditional_get true
258 action :create_if_missing
266 notifies :run, "execute[#{file}]", :immediately
267 notifies :restart, "service[renderd]"
271 nodejs_package "carto"
273 systemd_service "update-lowzoom@" do
274 description "Low zoom tile update service for %i layer"
276 exec_start "/bin/bash /usr/local/bin/update-lowzoom-%i"
280 protect_system "full"
282 no_new_privileges true
286 directory "/srv/tile.openstreetmap.org/styles" do
292 node[:tile][:styles].each do |name, details|
293 style_directory = "/srv/tile.openstreetmap.org/styles/#{name}"
294 tile_directory = "/srv/tile.openstreetmap.org/tiles/#{name}"
296 template "/usr/local/bin/update-lowzoom-#{name}" do
297 source "update-lowzoom.erb"
301 variables :style => name
304 service "update-lowzoom@#{name}" do
306 supports :restart => true
309 directory tile_directory do
315 details[:tile_directories].each do |directory|
316 directory directory[:name] do
322 directory[:min_zoom].upto(directory[:max_zoom]) do |zoom|
323 directory "#{directory[:name]}/#{zoom}" do
329 link "#{tile_directory}/#{zoom}" do
330 to "#{directory[:name]}/#{zoom}"
337 file "#{tile_directory}/planet-import-complete" do
338 action :create_if_missing
344 git style_directory do
346 repository details[:repository]
347 revision details[:revision]
352 link "#{style_directory}/data" do
353 to "/srv/tile.openstreetmap.org/data"
358 execute "#{style_directory}/project.mml" do
360 command "carto -a 3.0.0 project.mml > project.xml"
364 subscribes :run, "git[#{style_directory}]"
365 notifies :restart, "service[renderd]", :immediately
366 notifies :restart, "service[update-lowzoom@#{name}]"
370 postgresql_version = node[:tile][:database][:cluster].split("/").first
371 postgis_version = node[:tile][:database][:postgis]
373 package "postgresql-#{postgresql_version}-postgis-#{postgis_version}"
375 postgresql_user "jburgess" do
376 cluster node[:tile][:database][:cluster]
380 postgresql_user "tomh" do
381 cluster node[:tile][:database][:cluster]
385 postgresql_user "tile" do
386 cluster node[:tile][:database][:cluster]
389 postgresql_user "www-data" do
390 cluster node[:tile][:database][:cluster]
393 postgresql_database "gis" do
394 cluster node[:tile][:database][:cluster]
398 postgresql_extension "postgis" do
399 cluster node[:tile][:database][:cluster]
403 postgresql_extension "hstore" do
404 cluster node[:tile][:database][:cluster]
406 only_if { node[:tile][:database][:hstore] }
409 %w[geography_columns planet_osm_nodes planet_osm_rels planet_osm_ways raster_columns raster_overviews spatial_ref_sys].each do |table|
410 postgresql_table table do
411 cluster node[:tile][:database][:cluster]
414 permissions "tile" => :all
418 %w[geometry_columns planet_osm_line planet_osm_point planet_osm_polygon planet_osm_roads].each do |table|
419 postgresql_table table do
420 cluster node[:tile][:database][:cluster]
423 permissions "tile" => :all, "www-data" => :select
427 postgresql_munin "gis" do
428 cluster node[:tile][:database][:cluster]
432 directory File.dirname(node[:tile][:database][:node_file]) do
439 file node[:tile][:database][:node_file] do
445 directory "/var/log/tile" do
459 remote_directory "/usr/local/bin" do
469 template "/usr/local/bin/expire-tiles" do
470 source "expire-tiles.erb"
476 directory "/var/lib/replicate" do
482 directory "/var/lib/replicate/expire-queue" do
488 template "/usr/local/bin/replicate" do
489 source "replicate.erb"
493 variables :postgresql_version => postgresql_version.to_f
496 systemd_service "expire-tiles" do
497 description "Tile dirtying service"
500 exec_start "/usr/local/bin/expire-tiles"
501 standard_output "null"
504 protect_system "full"
506 no_new_privileges true
509 systemd_path "expire-tiles" do
510 description "Tile dirtying trigger"
511 directory_not_empty "/var/lib/replicate/expire-queue"
514 service "expire-tiles.path" do
515 action [:enable, :start]
516 subscribes :restart, "systemd_path[expire-tiles]"
519 systemd_service "replicate" do
520 description "Rendering database replication service"
521 after "postgresql.service"
522 wants "postgresql.service"
524 exec_start "/usr/local/bin/replicate"
527 protect_system "full"
529 no_new_privileges true
533 service "replicate" do
534 action [:enable, :start]
535 subscribes :restart, "template[/usr/local/bin/replicate]"
536 subscribes :restart, "systemd_service[replicate]"
539 template "/etc/logrotate.d/replicate" do
540 source "replicate.logrotate.erb"
546 template "/usr/local/bin/render-lowzoom" do
547 source "render-lowzoom.erb"
553 systemd_service "render-lowzoom" do
554 description "Render low zoom tiles"
556 exec_start "/usr/local/bin/render-lowzoom"
560 protect_system "full"
562 no_new_privileges true
565 systemd_timer "render-lowzoom" do
566 description "Render low zoom tiles"
567 on_calendar "Sun *-*~07/1 01:00:00"
570 service "render-lowzoom.timer" do
571 action [:enable, :start]
574 package "liblockfile-simple-perl"
575 package "libfilesys-df-perl"
577 template "/usr/local/bin/cleanup-tiles" do
578 source "cleanup-tiles.erb"
584 tile_directories = node[:tile][:styles].collect do |_, style|
585 style[:tile_directories].collect { |directory| directory[:name] }
586 end.flatten.sort.uniq
588 tile_directories.each do |directory|
589 label = directory.gsub("/", "-")
591 cron_d "cleanup-tiles#{label}" do
594 command "ionice -c 3 /usr/local/bin/cleanup-tiles #{directory}"
595 mailto "admins@openstreetmap.org"
599 munin_plugin "mod_tile_fresh"
600 munin_plugin "mod_tile_latency"
601 munin_plugin "mod_tile_response"
602 munin_plugin "mod_tile_zoom"
604 munin_plugin "renderd_processed"
605 munin_plugin "renderd_queue"
606 munin_plugin "renderd_queue_time"
607 munin_plugin "renderd_zoom"
608 munin_plugin "renderd_zoom_time"
610 munin_plugin "replication_delay"
612 prometheus_collector "modtile" do
616 prometheus_collector "renderd" do