From 74f83a16ba9bc172d9aa4432416041d33f383250 Mon Sep 17 00:00:00 2001 From: Tom Hughes Date: Thu, 23 Nov 2023 00:39:40 +0000 Subject: [PATCH] Run osm2pgsql replication in a loop instead of relying on Restart=always --- cookbooks/tile/recipes/default.rb | 15 ++++++++--- .../{replicate.erb => replicate-custom.erb} | 0 .../templates/default/replicate-osm2pgsql.erb | 26 +++++++++++++++++++ 3 files changed, 37 insertions(+), 4 deletions(-) rename cookbooks/tile/templates/default/{replicate.erb => replicate-custom.erb} (100%) create mode 100644 cookbooks/tile/templates/default/replicate-osm2pgsql.erb diff --git a/cookbooks/tile/recipes/default.rb b/cookbooks/tile/recipes/default.rb index 4df7c2554..3966954f8 100644 --- a/cookbooks/tile/recipes/default.rb +++ b/cookbooks/tile/recipes/default.rb @@ -543,7 +543,7 @@ end template "/usr/local/bin/replicate" do - source "replicate.erb" + source "replicate-custom.erb" owner "root" group "root" mode "755" @@ -609,6 +609,13 @@ mode "775" end + template "/usr/local/bin/replicate" do + source "replicate-osm2pgsql.erb" + owner "root" + group "root" + mode "755" + end + systemd_service "expire-tiles" do description "Tile dirtying service" type "simple" @@ -655,19 +662,19 @@ after "postgresql.service" wants "postgresql.service" user "tile" - exec_start "/bin/osm2pgsql-replication update --database gis --post-processing /usr/local/bin/replicate-post -- #{osm2pgsql_arguments.join(' ')}" + exec_start "/usr/local/bin/replicate" sandbox :enable_network => true restrict_address_families "AF_UNIX" read_write_paths [ "/store/database/nodes", "/var/lib/replicate" ] - restart "always" - restart_sec 30 + restart "on-failure" end service "replicate" do action [:enable, :start] + subscribes :restart, "template[/usr/local/bin/replicate]" subscribes :restart, "systemd_service[replicate]" end end diff --git a/cookbooks/tile/templates/default/replicate.erb b/cookbooks/tile/templates/default/replicate-custom.erb similarity index 100% rename from cookbooks/tile/templates/default/replicate.erb rename to cookbooks/tile/templates/default/replicate-custom.erb diff --git a/cookbooks/tile/templates/default/replicate-osm2pgsql.erb b/cookbooks/tile/templates/default/replicate-osm2pgsql.erb new file mode 100644 index 000000000..ee814b5d2 --- /dev/null +++ b/cookbooks/tile/templates/default/replicate-osm2pgsql.erb @@ -0,0 +1,26 @@ +#!/bin/sh + +# DO NOT EDIT - This file is being maintained by Chef + +while [ 1 = 1 ] +do + /bin/osm2pgsql-replication update \ + --database gis \ + --post-processing /usr/local/bin/replicate-post \ + -- \ + --number-processes=1 + --log-progress=false + --expire-tiles=13-19 + --expire-output=/var/lib/replicate/dirty-tiles.txt +<% if node[:tile][:database][:multi_geometry] -%> + --multi-geometry \ +<% end -%> +<% if node[:tile][:database][:hstore] -%> + --hstore \ +<% end -%> +<% if node[:tile][:database][:tag_transform_script] -%> + --tag-transform-script=<%= node[:tile][:database][:tag_transform_script] %> +<% end -%> + + sleep 30 +done