From b173c492c728598a8ad0e7fcba23fd2a127f6e78 Mon Sep 17 00:00:00 2001 From: Grant Slater Date: Tue, 3 Dec 2024 13:20:13 +0000 Subject: [PATCH] imagery: restart mapserver every hour to limit memory leak --- cookbooks/imagery/resources/site.rb | 19 +++++++++++++++++++ .../templates/default/nginx_imagery.conf.erb | 1 + 2 files changed, 20 insertions(+) diff --git a/cookbooks/imagery/resources/site.rb b/cookbooks/imagery/resources/site.rb index 856159be9..23771a4fc 100644 --- a/cookbooks/imagery/resources/site.rb +++ b/cookbooks/imagery/resources/site.rb @@ -139,6 +139,25 @@ action :create do not_if { new_resource.uses_tiler } end + # mapserver leaks memory, so restart it regularly. It is activated automatically by socket + systemd_service "mapserv-fcgi-#{new_resource.site}-stop" do + type "simple" + user "root" + exec_start "/bin/systemctl --quiet stop mapserv-fcgi-#{new_resource.site}.service" + sandbox true + restrict_address_families "AF_UNIX" + end + + systemd_timer "mapserv-fcgi-#{new_resource.site}-stop" do + on_boot_sec "10m" + on_unit_inactive_sec "1h" + randomized_delay_sec "10m" + end + + service "mapserv-fcgi-#{new_resource.site}-stop.timer" do + action [:enable, :start] + end + ssl_certificate new_resource.site do domains tile_domains end diff --git a/cookbooks/imagery/templates/default/nginx_imagery.conf.erb b/cookbooks/imagery/templates/default/nginx_imagery.conf.erb index 42ae9ac01..03a439343 100644 --- a/cookbooks/imagery/templates/default/nginx_imagery.conf.erb +++ b/cookbooks/imagery/templates/default/nginx_imagery.conf.erb @@ -15,6 +15,7 @@ upstream <%= @name %>_tiler_backend { <% else -%> upstream <%= @name %>_fastcgi { server "unix:/var/run/mapserver-fastcgi/layer-<%= @name %>.socket" max_fails=0; + server "unix:/var/run/./mapserver-fastcgi/layer-<%= @name %>.socket" max_fails=0; # Use default round-robin to distribute requests, rather than pick "fast" but maybe faulty. # Do not use keepalive -- 2.39.5