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 # http://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 "apache"
22 include_recipe "nodejs"
23 include_recipe "postgresql"
24 include_recipe "python"
25 include_recipe "tools"
27 blocks = data_bag_item("tile", "blocks")
28 web_passwords = data_bag_item("web", "passwords")
32 apache_module "expires"
33 apache_module "headers"
34 apache_module "remoteip"
35 apache_module "rewrite"
37 apache_module "tile" do
41 tilecaches = search(:node, "roles:tilecache").sort_by { |n| n[:hostname] }
43 apache_site "default" do
47 apache_site "tile.openstreetmap.org" do
49 variables :caches => tilecaches
52 template "/etc/logrotate.d/apache2" do
53 source "logrotate.apache.erb"
59 directory "/srv/tile.openstreetmap.org" do
67 systemd_service "renderd" do
68 description "Mapnik rendering daemon"
69 after "postgresql.service"
70 wants "postgresql.service"
72 exec_start "/usr/bin/renderd -f"
73 runtime_directory "renderd"
80 no_new_privileges true
85 action [:enable, :start]
86 subscribes :restart, "systemd_service[renderd]"
89 directory "/srv/tile.openstreetmap.org/tiles" do
95 template "/etc/renderd.conf" do
96 source "renderd.conf.erb"
100 notifies :reload, "service[apache2]"
101 notifies :restart, "service[renderd]"
104 remote_directory "/srv/tile.openstreetmap.org/html" do
114 template "/srv/tile.openstreetmap.org/html/index.html" do
115 source "index.html.erb"
121 package "python-cairo"
122 package "python-mapnik"
123 package "python-setuptools"
125 python_package "pyotp"
127 package "fonts-noto-cjk"
128 package "fonts-noto-hinted"
129 package "fonts-noto-unhinted"
130 package "fonts-hanazono"
131 package "ttf-unifont"
133 ["NotoSansArabicUI-Regular.ttf", "NotoSansArabicUI-Bold.ttf"].each do |font|
134 remote_file "/usr/share/fonts/truetype/noto/#{font}" do
135 action :create_if_missing
136 source "https://github.com/googlei18n/noto-fonts/raw/master/hinted/#{font}"
143 directory "/srv/tile.openstreetmap.org/cgi-bin" do
149 template "/srv/tile.openstreetmap.org/cgi-bin/export" do
154 variables :blocks => blocks, :totp_key => web_passwords["totp_key"]
157 template "/srv/tile.openstreetmap.org/cgi-bin/debug" do
164 template "/etc/cron.hourly/export" do
165 source "export.cron.erb"
171 directory "/srv/tile.openstreetmap.org/data" do
177 package "mapnik-utils"
179 node[:tile][:data].each_value do |data|
181 file = "/srv/tile.openstreetmap.org/data/#{File.basename(url)}"
184 directory = "/srv/tile.openstreetmap.org/data/#{data[:directory]}"
186 directory directory do
192 directory = "/srv/tile.openstreetmap.org/data"
200 command "tar -zxf #{file} -C #{directory}"
204 elsif file =~ /\.tar\.bz2$/
209 command "tar -jxf #{file} -C #{directory}"
213 elsif file =~ /\.zip$/
218 command "unzip -qq -o #{file} -d #{directory}"
224 execute "#{file}_shapeindex" do
226 command "find #{directory} -type f -iname '*.shp' -print0 | xargs -0 --no-run-if-empty shapeindex --shape_files"
229 subscribes :run, "execute[#{file}]", :immediately
235 use_conditional_get true
238 action :create_if_missing
246 notifies :run, "execute[#{file}]", :immediately
247 notifies :restart, "service[renderd]"
251 nodejs_package "carto"
252 nodejs_package "millstone"
254 systemd_service "update-lowzoom@" do
255 description "Low zoom tile update service for %i layer"
257 exec_start "/bin/bash /usr/local/bin/update-lowzoom-%i"
261 protect_system "full"
263 no_new_privileges true
267 directory "/srv/tile.openstreetmap.org/styles" do
273 node[:tile][:styles].each do |name, details|
274 style_directory = "/srv/tile.openstreetmap.org/styles/#{name}"
275 tile_directory = "/srv/tile.openstreetmap.org/tiles/#{name}"
277 template "/usr/local/bin/update-lowzoom-#{name}" do
278 source "update-lowzoom.erb"
282 variables :style => name
285 service "update-lowzoom@#{name}" do
287 supports :restart => true
290 directory tile_directory do
296 details[:tile_directories].each do |directory|
297 directory directory[:name] do
303 directory[:min_zoom].upto(directory[:max_zoom]) do |zoom|
304 directory "#{directory[:name]}/#{zoom}" do
310 link "#{tile_directory}/#{zoom}" do
311 to "#{directory[:name]}/#{zoom}"
318 file "#{tile_directory}/planet-import-complete" do
319 action :create_if_missing
325 git style_directory do
327 repository details[:repository]
328 revision details[:revision]
333 link "#{style_directory}/data" do
334 to "/srv/tile.openstreetmap.org/data"
339 execute "#{style_directory}/project.mml" do
341 command "carto -a 3.0.0 project.mml > project.xml"
345 subscribes :run, "git[#{style_directory}]"
346 notifies :restart, "service[renderd]", :immediately
347 notifies :restart, "service[update-lowzoom@#{name}]"
351 postgresql_version = node[:tile][:database][:cluster].split("/").first
354 package "postgresql-#{postgresql_version}-postgis-2.3"
356 postgresql_user "jburgess" do
357 cluster node[:tile][:database][:cluster]
361 postgresql_user "tomh" do
362 cluster node[:tile][:database][:cluster]
366 postgresql_user "tile" do
367 cluster node[:tile][:database][:cluster]
370 postgresql_user "www-data" do
371 cluster node[:tile][:database][:cluster]
374 postgresql_database "gis" do
375 cluster node[:tile][:database][:cluster]
379 postgresql_extension "postgis" do
380 cluster node[:tile][:database][:cluster]
384 postgresql_extension "hstore" do
385 cluster node[:tile][:database][:cluster]
389 %w[geography_columns planet_osm_nodes planet_osm_rels planet_osm_ways raster_columns raster_overviews spatial_ref_sys].each do |table|
390 postgresql_table table do
391 cluster node[:tile][:database][:cluster]
394 permissions "tile" => :all
398 %w[geometry_columns planet_osm_line planet_osm_point planet_osm_polygon planet_osm_roads].each do |table|
399 postgresql_table table do
400 cluster node[:tile][:database][:cluster]
403 permissions "tile" => :all, "www-data" => :select
407 postgresql_munin "gis" do
408 cluster node[:tile][:database][:cluster]
412 file node[:tile][:node_file] do
418 directory "/var/log/tile" do
430 package "libproj-dev"
431 package "libxml2-dev"
433 gem_package "proj4rb"
434 gem_package "libxml-ruby"
436 remote_directory "/usr/local/lib/site_ruby" do
446 template "/usr/local/bin/expire-tiles" do
447 source "expire-tiles.erb"
453 directory "/var/lib/replicate" do
459 directory "/var/lib/replicate/expire-queue" do
465 template "/var/lib/replicate/configuration.txt" do
466 source "replicate.configuration.erb"
472 template "/usr/local/bin/replicate" do
473 source "replicate.erb"
479 systemd_service "expire-tiles" do
480 description "Tile dirtying service"
483 exec_start "/usr/local/bin/expire-tiles"
484 standard_output "null"
487 protect_system "full"
489 no_new_privileges true
492 systemd_path "expire-tiles" do
493 description "Tile dirtying trigger"
494 directory_not_empty "/var/lib/replicate/expire-queue"
497 service "expire-tiles.path" do
498 action [:enable, :start]
499 subscribes :restart, "systemd_path[expire-tiles]"
502 systemd_service "replicate" do
503 description "Rendering database replication service"
504 after "postgresql.service"
505 wants "postgresql.service"
507 exec_start "/usr/local/bin/replicate"
510 protect_system "full"
512 no_new_privileges true
516 service "replicate" do
517 action [:enable, :start]
518 subscribes :restart, "template[/usr/local/bin/replicate]"
519 subscribes :restart, "systemd_service[replicate]"
522 template "/etc/logrotate.d/replicate" do
523 source "replicate.logrotate.erb"
529 template "/usr/local/bin/render-lowzoom" do
530 source "render-lowzoom.erb"
536 template "/etc/cron.d/render-lowzoom" do
537 source "render-lowzoom.cron.erb"
543 package "liblockfile-simple-perl"
544 package "libfilesys-df-perl"
546 template "/usr/local/bin/cleanup-tiles" do
547 source "cleanup-tiles.erb"
553 tile_directories = node[:tile][:styles].collect do |_, style|
554 style[:tile_directories].collect { |directory| directory[:name] }
555 end.flatten.sort.uniq
557 template "/etc/cron.d/cleanup-tiles" do
558 source "cleanup-tiles.cron.erb"
562 variables :directories => tile_directories
565 munin_plugin "mod_tile_fresh"
566 munin_plugin "mod_tile_latency"
567 munin_plugin "mod_tile_response"
568 munin_plugin "mod_tile_zoom"
570 munin_plugin "renderd_processed"
571 munin_plugin "renderd_queue"
572 munin_plugin "renderd_queue_time"
573 munin_plugin "renderd_zoom"
574 munin_plugin "renderd_zoom_time"
576 munin_plugin "replication_delay" do