X-Git-Url: https://git.openstreetmap.org/chef.git/blobdiff_plain/52cd38fa82f0eb1febb5cca9ddbf62253e15e620..68e068818d559ef35bdf2a138a93596337828ef9:/cookbooks/tile/recipes/default.rb diff --git a/cookbooks/tile/recipes/default.rb b/cookbooks/tile/recipes/default.rb index fe5934a61..d1a394b2f 100644 --- a/cookbooks/tile/recipes/default.rb +++ b/cookbooks/tile/recipes/default.rb @@ -29,6 +29,7 @@ include_recipe "ruby" include_recipe "tools" blocks = data_bag_item("tile", "blocks") +admins = data_bag_item("apache", "admins") web_passwords = data_bag_item("web", "passwords") apache_module "alias" @@ -59,6 +60,14 @@ end fastlyips = JSON.parse(IO.read("#{Chef::Config[:file_cache_path]}/fastly-ip-list.json")) +remote_file "#{Chef::Config[:file_cache_path]}/statuscake-locations.json" do + source "https://app.statuscake.com/Workfloor/Locations.php?format=json" + compile_time true + ignore_failure true +end + +statuscakelocations = JSON.parse(IO.read("#{Chef::Config[:file_cache_path]}/statuscake-locations.json")) + apache_site "default" do action :disable end @@ -69,7 +78,9 @@ end apache_site "tile.openstreetmap.org" do template "apache.erb" - variables :fastly => fastlyips["addresses"] + variables :fastly => fastlyips["addresses"] + fastlyips["ipv6_addresses"], + :statuscake => statuscakelocations.flat_map { |_, v| [v["ip"], v["ipv6"]] }, + :admins => admins["hosts"] end template "/etc/logrotate.d/apache2" do @@ -97,6 +108,10 @@ file "/srv/tile.openstreetmap.org/conf/ip.map" do mode "644" end +tile_directories = node[:tile][:styles].collect do |_, style| + style[:tile_directories].collect { |directory| directory[:name] } +end.flatten.sort.uniq + package "renderd" systemd_service "renderd" do @@ -104,19 +119,12 @@ systemd_service "renderd" do after "postgresql.service" wants "postgresql.service" limit_nofile 4096 - private_tmp true - private_devices true - private_network true - protect_system "full" - protect_home true - no_new_privileges true + sandbox true + restrict_address_families "AF_UNIX" + read_write_paths tile_directories restart "on-failure" end -systemd_service "renderd" do - action :delete -end - service "renderd" do action [:enable, :start] subscribes :restart, "systemd_service[renderd]" @@ -186,11 +194,22 @@ template "/srv/tile.openstreetmap.org/cgi-bin/debug" do mode "755" end -template "/etc/cron.hourly/export" do - source "export.cron.erb" - owner "root" - group "root" - mode "755" +systemd_service "export-cleanup" do + description "Cleanup stale export temporary files" + joins_namespace_of "apache2.service" + exec_start "find /tmp -ignore_readdir_race -name 'export??????' -mmin +60 -delete" + user "www-data" + sandbox true +end + +systemd_timer "export-cleanup" do + description "Cleanup stale export temporary files" + on_boot_sec "60m" + on_unit_inactive_sec "60m" +end + +service "export-cleanup.timer" do + action [:enable, :start] end directory "/srv/tile.openstreetmap.org/data" do @@ -275,20 +294,16 @@ nodejs_package "carto" systemd_service "update-lowzoom@" do description "Low zoom tile update service for %i layer" - conflicts "render-lowzoom.service" user "tile" + exec_start_pre "+/bin/systemctl stop render-lowzoom.service" exec_start "/bin/bash /usr/local/bin/update-lowzoom-%i" runtime_directory "update-lowzoom-%i" - private_tmp true - private_devices true - private_network true - protect_system "strict" - protect_home true + sandbox true + restrict_address_families "AF_UNIX" read_write_paths [ "/srv/tile.openstreetmap.org/tiles/%i", "/var/log/tile" ] - no_new_privileges true restart "on-failure" end @@ -377,7 +392,7 @@ node[:tile][:styles].each do |name, details| execute "#{style_directory}/project.mml" do action :nothing - command "carto -a 3.0.0 project.mml > project.xml" + command "carto -a 3.0.22 project.mml > project.xml" cwd style_directory user "tile" group "tile" @@ -545,13 +560,8 @@ systemd_service "tile-ratelimit" do group "adm" exec_start "/usr/local/bin/tile-ratelimit" nice 10 - private_tmp true - private_devices true - private_network true - protect_system "strict" - protect_home true + sandbox true read_write_paths "/srv/tile.openstreetmap.org/conf" - no_new_privileges true restart "on-failure" end @@ -595,17 +605,12 @@ systemd_service "expire-tiles" do exec_start "/usr/local/bin/expire-tiles" nice 10 standard_output "null" - private_tmp true - private_devices true - protect_system "strict" - protect_home true - read_write_paths [ + sandbox true + read_write_paths tile_directories + [ "/store/database/nodes", - "/store/tiles/%i", "/var/lib/replicate/expire-queue", "/var/log/tile" ] - no_new_privileges true end systemd_path "expire-tiles" do @@ -624,16 +629,13 @@ systemd_service "replicate" do wants "postgresql.service" user "tile" exec_start "/usr/local/bin/replicate" - private_tmp true - private_devices true - protect_system "strict" - protect_home true + sandbox :enable_network => true + restrict_address_families "AF_UNIX" read_write_paths [ "/store/database/nodes", "/var/lib/replicate", "/var/log/tile" ] - no_new_privileges true restart "on-failure" end @@ -662,13 +664,9 @@ systemd_service "render-lowzoom" do condition_path_exists_glob "!/run/update-lowzoom-*" user "tile" exec_start "/usr/local/bin/render-lowzoom" - private_tmp true - private_devices true - private_network true - protect_system "strict" - protect_home true + sandbox true + restrict_address_families "AF_UNIX" read_write_paths "/var/log/tile" - no_new_privileges true end systemd_timer "render-lowzoom" do @@ -690,18 +688,27 @@ template "/usr/local/bin/cleanup-tiles" do mode "755" end -tile_directories = node[:tile][:styles].collect do |_, style| - style[:tile_directories].collect { |directory| directory[:name] } -end.flatten.sort.uniq +systemd_service "cleanup-tiles@" do + description "Cleanup old tiles for /%I" + exec_start "/usr/local/bin/cleanup-tiles /%I" + user "_renderd" + io_scheduling_class "idle" + sandbox true + read_write_paths "/%I" +end + +systemd_timer "cleanup-tiles@" do + description "Cleanup old tiles for /%I" + on_boot_sec "30m" + on_unit_inactive_sec "60m" + randomized_delay_sec "10m" +end tile_directories.each do |directory| - label = directory.gsub("/", "-") + label = directory[1..].gsub("/", "-") - cron_d "cleanup-tiles#{label}" do - minute "0" - user "_renderd" - command "ionice -c 3 /usr/local/bin/cleanup-tiles #{directory}" - mailto "admins@openstreetmap.org" + service "cleanup-tiles@#{label}.timer" do + action [:enable, :start] end end