From: Tom Hughes Date: Thu, 23 Nov 2023 00:10:51 +0000 (+0000) Subject: Run expiry as a separate service for osm2pgsql replication X-Git-Url: https://git.openstreetmap.org./chef.git/commitdiff_plain/5d6af18552445fde805e19bf1b3e2b9c48cf1cf7 Run expiry as a separate service for osm2pgsql replication --- diff --git a/cookbooks/tile/recipes/default.rb b/cookbooks/tile/recipes/default.rb index 41c63cd4f..4df7c2554 100644 --- a/cookbooks/tile/recipes/default.rb +++ b/cookbooks/tile/recipes/default.rb @@ -596,24 +596,44 @@ if node[:tile][:replication][:engine] == "custom" subscribes :restart, "systemd_service[replicate]" end elsif node[:tile][:replication][:engine] == "osm2pgsql" - service "expire-tiles.path" do - action [:disable, :stop] + template "/usr/local/bin/expire-tiles" do + source "expire-tiles-osm2pgsql.erb" + owner "root" + group "root" + mode "755" end - systemd_path "expire-tiles" do - action :delete + directory "/var/lib/replicate/expire-queue" do + owner "tile" + group "_renderd" + mode "775" + end + + systemd_service "expire-tiles" do + description "Tile dirtying service" + type "simple" + user "_renderd" + exec_start "/usr/local/bin/expire-tiles" + nice 10 + sandbox true + restrict_address_families "AF_UNIX" + read_write_paths tile_directories + [ + "/var/lib/replicate/expire-queue" + ] end - service "expire-tiles" do - action :stop + systemd_path "expire-tiles" do + description "Tile dirtying trigger" + directory_not_empty "/var/lib/replicate/expire-queue" end - systemd_service "expire-tiles" do - action :delete + service "expire-tiles.path" do + action [:enable, :start] + subscribes :restart, "systemd_path[expire-tiles]" end - template "/usr/local/bin/expire-tiles" do - source "expire-tiles-osm2pgsql.erb" + template "/usr/local/bin/replicate-post" do + source "replicate-post.erb" owner "root" group "root" mode "755" @@ -635,11 +655,10 @@ elsif node[:tile][:replication][:engine] == "osm2pgsql" after "postgresql.service" wants "postgresql.service" user "tile" - exec_start "/bin/osm2pgsql-replication update --database gis --post-processing /usr/local/bin/expire-tiles -- #{osm2pgsql_arguments.join(' ')}" + exec_start "/bin/osm2pgsql-replication update --database gis --post-processing /usr/local/bin/replicate-post -- #{osm2pgsql_arguments.join(' ')}" sandbox :enable_network => true restrict_address_families "AF_UNIX" - read_write_paths tile_directories + [ - "/srv/tile.openstreetmap.org/tiles", + read_write_paths [ "/store/database/nodes", "/var/lib/replicate" ] diff --git a/cookbooks/tile/templates/default/expire-tiles-osm2pgsql.erb b/cookbooks/tile/templates/default/expire-tiles-osm2pgsql.erb index 0ad14e803..1af7f0a64 100644 --- a/cookbooks/tile/templates/default/expire-tiles-osm2pgsql.erb +++ b/cookbooks/tile/templates/default/expire-tiles-osm2pgsql.erb @@ -1,18 +1,17 @@ -#!/bin/sh -e +#!/usr/bin/ruby # DO NOT EDIT - This file is being maintained by Chef -sequence="$1" -timestamp="$2" +args = [ + "--socket=/var/run/renderd/renderd.sock", + "--tile-dir=/srv/tile.openstreetmap.org/tiles", + "--touch-from=13", + "--min-zoom=13" +] -render_expired \ - --map=default \ - --socket=/var/run/renderd/renderd.sock \ - --tile-dir=/srv/tile.openstreetmap.org/tiles \ - --min-zoom=13 --max-zoom=19 \ - --touch-from=13 < /var/lib/replicate/dirty-tiles.txt - -rm -f /var/lib/replicate/dirty-tiles.txt - -echo "$sequence" > /var/log/replicate/sequence.txt -echo "$timestamp" > /var/log/replicate/timestamp.txt +Dir.glob("/var/lib/replicate/expire-queue/changes-*.txt").sort.each do |f| + <% node[:tile][:styles].each do |name,details| -%> + system("/usr/bin/render_expired", "--map=<%= name %>", *args, "--max-zoom=<%= details[:max_zoom] %>", :in=> f) && + <% end -%> + File::unlink(f) +end diff --git a/cookbooks/tile/templates/default/replicate-post.erb b/cookbooks/tile/templates/default/replicate-post.erb new file mode 100644 index 000000000..63ca93b8c --- /dev/null +++ b/cookbooks/tile/templates/default/replicate-post.erb @@ -0,0 +1,11 @@ +#!/bin/sh -e + +# DO NOT EDIT - This file is being maintained by Chef + +sequence="$1" +timestamp="$2" + +mv /var/lib/replicate/dirty-tiles.txt /var/lib/replicate/expire-queue/changes-${sequence}.txt + +echo "$sequence" > /var/lib/replicate/sequence.txt +echo "$timestamp" > /var/lib/replicate/timestamp.txt