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"
487 systemd_service "expire-tiles" do
488 description "Tile dirtying service"
491 exec_start "/usr/local/bin/expire-tiles"
492 standard_output "null"
495 protect_system "full"
497 no_new_privileges true
500 systemd_path "expire-tiles" do
501 description "Tile dirtying trigger"
502 directory_not_empty "/var/lib/replicate/expire-queue"
505 service "expire-tiles.path" do
506 action [:enable, :start]
507 subscribes :restart, "systemd_path[expire-tiles]"
510 systemd_service "replicate" do
511 description "Rendering database replication service"
512 after "postgresql.service"
513 wants "postgresql.service"
515 exec_start "/usr/local/bin/replicate"
518 protect_system "full"
520 no_new_privileges true
524 service "replicate" do
525 action [:enable, :start]
526 subscribes :restart, "template[/usr/local/bin/replicate]"
527 subscribes :restart, "systemd_service[replicate]"
530 template "/etc/logrotate.d/replicate" do
531 source "replicate.logrotate.erb"
537 template "/usr/local/bin/render-lowzoom" do
538 source "render-lowzoom.erb"
544 systemd_service "render-lowzoom" do
545 description "Render low zoom tiles"
547 exec_start "/usr/local/bin/render-lowzoom"
551 protect_system "full"
553 no_new_privileges true
556 systemd_timer "render-lowzoom" do
557 description "Render low zoom tiles"
558 on_calendar "Sun *-*~07/1 01:00:00"
561 service "render-lowzoom.timer" do
562 action [:enable, :start]
565 file "/etc/cron.d/render-lowzoom" do
569 package "liblockfile-simple-perl"
570 package "libfilesys-df-perl"
572 template "/usr/local/bin/cleanup-tiles" do
573 source "cleanup-tiles.erb"
579 tile_directories = node[:tile][:styles].collect do |_, style|
580 style[:tile_directories].collect { |directory| directory[:name] }
581 end.flatten.sort.uniq
583 template "/etc/cron.d/cleanup-tiles" do
584 source "cleanup-tiles.cron.erb"
588 variables :directories => tile_directories
591 munin_plugin "mod_tile_fresh"
592 munin_plugin "mod_tile_latency"
593 munin_plugin "mod_tile_response"
594 munin_plugin "mod_tile_zoom"
596 munin_plugin "renderd_processed"
597 munin_plugin "renderd_queue"
598 munin_plugin "renderd_queue_time"
599 munin_plugin "renderd_zoom"
600 munin_plugin "renderd_zoom_time"
602 munin_plugin "replication_delay"