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 "python"
27 include_recipe "tools"
29 blocks = data_bag_item("tile", "blocks")
30 web_passwords = data_bag_item("web", "passwords")
34 apache_module "expires"
35 apache_module "headers"
36 apache_module "remoteip"
37 apache_module "rewrite"
39 apache_module "tile" do
43 ssl_certificate node[:fqdn] do
44 domains [node[:fqdn], "tile.openstreetmap.org", "render.openstreetmap.org"]
45 notifies :reload, "service[apache2]"
48 tilecaches = search(:node, "roles:tilecache").sort_by { |n| n[:hostname] }
50 apache_site "default" do
54 apache_site "tile.openstreetmap.org" do
56 variables :caches => tilecaches
59 template "/etc/logrotate.d/apache2" do
60 source "logrotate.apache.erb"
66 directory "/srv/tile.openstreetmap.org" do
74 systemd_service "renderd" do
75 description "Mapnik rendering daemon"
76 after "postgresql.service"
77 wants "postgresql.service"
79 exec_start "/usr/bin/renderd -f"
80 runtime_directory "renderd"
87 no_new_privileges true
92 action [:enable, :start]
93 subscribes :restart, "systemd_service[renderd]"
96 directory "/srv/tile.openstreetmap.org/tiles" do
102 template "/etc/renderd.conf" do
103 source "renderd.conf.erb"
107 notifies :reload, "service[apache2]"
108 notifies :restart, "service[renderd]"
111 remote_directory "/srv/tile.openstreetmap.org/html" do
121 template "/srv/tile.openstreetmap.org/html/index.html" do
122 source "index.html.erb"
134 python_package "pyotp"
144 ["NotoSansArabicUI-Regular.ttf", "NotoSansArabicUI-Bold.ttf"].each do |font|
145 remote_file "/usr/share/fonts/truetype/noto/#{font}" do
146 action :create_if_missing
147 source "https://github.com/googlei18n/noto-fonts/raw/master/hinted/#{font}"
154 directory "/srv/tile.openstreetmap.org/cgi-bin" do
160 template "/srv/tile.openstreetmap.org/cgi-bin/export" do
165 variables :blocks => blocks, :totp_key => web_passwords["totp_key"]
168 template "/srv/tile.openstreetmap.org/cgi-bin/debug" do
175 template "/etc/cron.hourly/export" do
176 source "export.cron.erb"
182 directory "/srv/tile.openstreetmap.org/data" do
188 package "mapnik-utils"
190 node[:tile][:data].each_value do |data|
192 file = "/srv/tile.openstreetmap.org/data/#{File.basename(url)}"
195 directory = "/srv/tile.openstreetmap.org/data/#{data[:directory]}"
197 directory directory do
203 directory = "/srv/tile.openstreetmap.org/data"
211 command "tar -zxf #{file} -C #{directory}"
215 elsif file =~ /\.tar\.bz2$/
220 command "tar -jxf #{file} -C #{directory}"
224 elsif file =~ /\.zip$/
229 command "unzip -qq -o #{file} -d #{directory}"
235 execute "#{file}_shapeindex" do
237 command "find #{directory} -type f -iname '*.shp' -print0 | xargs -0 --no-run-if-empty shapeindex --shape_files"
240 subscribes :run, "execute[#{file}]", :immediately
246 use_conditional_get true
249 action :create_if_missing
257 notifies :run, "execute[#{file}]", :immediately
258 notifies :restart, "service[renderd]"
262 nodejs_package "carto"
263 nodejs_package "millstone"
265 systemd_service "update-lowzoom@" do
266 description "Low zoom tile update service for %i layer"
268 exec_start "/bin/bash /usr/local/bin/update-lowzoom-%i"
272 protect_system "full"
274 no_new_privileges true
278 directory "/srv/tile.openstreetmap.org/styles" do
284 node[:tile][:styles].each do |name, details|
285 style_directory = "/srv/tile.openstreetmap.org/styles/#{name}"
286 tile_directory = "/srv/tile.openstreetmap.org/tiles/#{name}"
288 template "/usr/local/bin/update-lowzoom-#{name}" do
289 source "update-lowzoom.erb"
293 variables :style => name
296 service "update-lowzoom@#{name}" do
298 supports :restart => true
301 directory tile_directory do
307 details[:tile_directories].each do |directory|
308 directory directory[:name] do
314 directory[:min_zoom].upto(directory[:max_zoom]) do |zoom|
315 directory "#{directory[:name]}/#{zoom}" do
321 link "#{tile_directory}/#{zoom}" do
322 to "#{directory[:name]}/#{zoom}"
329 file "#{tile_directory}/planet-import-complete" do
330 action :create_if_missing
336 git style_directory do
338 repository details[:repository]
339 revision details[:revision]
344 link "#{style_directory}/data" do
345 to "/srv/tile.openstreetmap.org/data"
350 execute "#{style_directory}/project.mml" do
352 command "carto -a 3.0.0 project.mml > project.xml"
356 subscribes :run, "git[#{style_directory}]"
357 notifies :restart, "service[renderd]", :immediately
358 notifies :restart, "service[update-lowzoom@#{name}]"
362 postgresql_version = node[:tile][:database][:cluster].split("/").first
363 postgis_version = node[:tile][:database][:postgis]
365 package "postgresql-#{postgresql_version}-postgis-#{postgis_version}"
367 postgresql_user "jburgess" do
368 cluster node[:tile][:database][:cluster]
372 postgresql_user "tomh" do
373 cluster node[:tile][:database][:cluster]
377 postgresql_user "tile" do
378 cluster node[:tile][:database][:cluster]
381 postgresql_user "www-data" do
382 cluster node[:tile][:database][:cluster]
385 postgresql_database "gis" do
386 cluster node[:tile][:database][:cluster]
390 postgresql_extension "postgis" do
391 cluster node[:tile][:database][:cluster]
395 postgresql_extension "hstore" do
396 cluster node[:tile][:database][:cluster]
398 only_if { node[:tile][:database][:hstore] }
401 %w[geography_columns planet_osm_nodes planet_osm_rels planet_osm_ways raster_columns raster_overviews spatial_ref_sys].each do |table|
402 postgresql_table table do
403 cluster node[:tile][:database][:cluster]
406 permissions "tile" => :all
410 %w[geometry_columns planet_osm_line planet_osm_point planet_osm_polygon planet_osm_roads].each do |table|
411 postgresql_table table do
412 cluster node[:tile][:database][:cluster]
415 permissions "tile" => :all, "www-data" => :select
419 postgresql_munin "gis" do
420 cluster node[:tile][:database][:cluster]
424 directory File.dirname(node[:tile][:database][:node_file]) do
431 file node[:tile][:database][:node_file] do
437 directory "/var/log/tile" do
451 remote_directory "/usr/local/bin" do
461 template "/usr/local/bin/expire-tiles" do
462 source "expire-tiles.erb"
468 directory "/var/lib/replicate" do
474 directory "/var/lib/replicate/expire-queue" do
480 template "/usr/local/bin/replicate" do
481 source "replicate.erb"
485 variables :postgresql_version => postgresql_version.to_f
488 systemd_service "expire-tiles" do
489 description "Tile dirtying service"
492 exec_start "/usr/local/bin/expire-tiles"
493 standard_output "null"
496 protect_system "full"
498 no_new_privileges true
501 systemd_path "expire-tiles" do
502 description "Tile dirtying trigger"
503 directory_not_empty "/var/lib/replicate/expire-queue"
506 service "expire-tiles.path" do
507 action [:enable, :start]
508 subscribes :restart, "systemd_path[expire-tiles]"
511 systemd_service "replicate" do
512 description "Rendering database replication service"
513 after "postgresql.service"
514 wants "postgresql.service"
516 exec_start "/usr/local/bin/replicate"
519 protect_system "full"
521 no_new_privileges true
525 service "replicate" do
526 action [:enable, :start]
527 subscribes :restart, "template[/usr/local/bin/replicate]"
528 subscribes :restart, "systemd_service[replicate]"
531 template "/etc/logrotate.d/replicate" do
532 source "replicate.logrotate.erb"
538 template "/usr/local/bin/render-lowzoom" do
539 source "render-lowzoom.erb"
545 systemd_service "render-lowzoom" do
546 description "Render low zoom tiles"
548 exec_start "/usr/local/bin/render-lowzoom"
552 protect_system "full"
554 no_new_privileges true
557 systemd_timer "render-lowzoom" do
558 description "Render low zoom tiles"
559 on_calendar "Sun *-*~07/1 01:00:00"
562 service "render-lowzoom.timer" do
563 action [:enable, :start]
566 file "/etc/cron.d/render-lowzoom" do
570 package "liblockfile-simple-perl"
571 package "libfilesys-df-perl"
573 template "/usr/local/bin/cleanup-tiles" do
574 source "cleanup-tiles.erb"
580 tile_directories = node[:tile][:styles].collect do |_, style|
581 style[:tile_directories].collect { |directory| directory[:name] }
582 end.flatten.sort.uniq
584 template "/etc/cron.d/cleanup-tiles" do
585 source "cleanup-tiles.cron.erb"
589 variables :directories => tile_directories
592 munin_plugin "mod_tile_fresh"
593 munin_plugin "mod_tile_latency"
594 munin_plugin "mod_tile_response"
595 munin_plugin "mod_tile_zoom"
597 munin_plugin "renderd_processed"
598 munin_plugin "renderd_queue"
599 munin_plugin "renderd_queue_time"
600 munin_plugin "renderd_zoom"
601 munin_plugin "renderd_zoom_time"
603 munin_plugin "replication_delay"