From 3ba375a4188ecb15c725a0e9ab6c6f2951f0073b Mon Sep 17 00:00:00 2001 From: Amanda McCann Date: Fri, 31 Jan 2025 13:11:03 +0100 Subject: [PATCH 1/3] minor refactor to use a constant in Tirex instead of raw numbers. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Systemd list exit code 2 as “Invalid or excess arguments.” --- bin/tirex-backend-manager | 4 ++-- lib/Tirex.pm | 1 + 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/bin/tirex-backend-manager b/bin/tirex-backend-manager index a7aa3f1..977f396 100755 --- a/bin/tirex-backend-manager +++ b/bin/tirex-backend-manager @@ -55,7 +55,7 @@ die("refusing to run as root\n") if ($< == 0); my @argv = @ARGV; my %opts = (); -GetOptions( \%opts, 'help|h', 'debug|d', 'foreground|f', 'config|c=s' ) or exit(2); +GetOptions( \%opts, 'help|h', 'debug|d', 'foreground|f', 'config|c=s' ) or exit($Tirex::EXIT_CODE_INVALIDARGUMENT); if ($opts{'help'}) { @@ -375,7 +375,7 @@ sub cleanup_dead_workers { my $renderer = $workers->{$pid}->{'renderer'}; syslog('err', 'terminating due to unexpected error in renderer %s', $renderer->get_name()); - exit_gracefully(2); + exit_gracefully($Tirex::EXIT_CODE_INVALIDARGUMENT); } $workers->{$pid}->{'handle'}->close(); diff --git a/lib/Tirex.pm b/lib/Tirex.pm index 5caa1a3..2c605ab 100644 --- a/lib/Tirex.pm +++ b/lib/Tirex.pm @@ -44,6 +44,7 @@ our $MAX_PACKET_SIZE = 512; # max zoom level we will ever allow our $MAX_ZOOM = 30; +our $EXIT_CODE_INVALIDARGUMENT = 2; our $EXIT_CODE_RESTART = 9; our $EXIT_CODE_DISABLE = 10; From b13f49809c5b21d2cb643ab42fd0aa3512a75df3 Mon Sep 17 00:00:00 2001 From: Amanda McCann Date: Fri, 31 Jan 2025 13:18:22 +0100 Subject: [PATCH 2/3] Exit if a mapnik style can't be created. If there is a problem initializing a map style, this patch will cause the mapnik backend to exit (with 2). This causes the complete tirex-backend-manager process to exit with 2. The previous behaviour was for it to constantly attempt to initialize the map forevery A mapnik style can fail to load for many reasons, such as missing database tables. This change means incorrectly set up servers can be detected quicker. --- backend-mapnik/renderd.cc | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/backend-mapnik/renderd.cc b/backend-mapnik/renderd.cc index 2d9d235..a515fde 100644 --- a/backend-mapnik/renderd.cc +++ b/backend-mapnik/renderd.cc @@ -238,7 +238,10 @@ RenderDaemon::RenderDaemon(int argc, char **argv) : char *tkn = strtok(dup, " "); while (tkn) { - loadMapnikWrapper(tkn); + if (!loadMapnikWrapper(tkn)) { + warning("Unable to load map"); + exit(2); + } tkn = strtok(NULL, " "); } } From b503aebd7315440bd825ffe047a5d7e6e30e3885 Mon Sep 17 00:00:00 2001 From: Amanda McCann Date: Fri, 31 Jan 2025 13:27:56 +0100 Subject: [PATCH 3/3] Systemd won't restart t-b-m if it fails with exit 2 (which should be caused by bad config) Currently systemd will constantly try to restart tirex-backend-manager if it fails, forever and every. This change makes systemd not try to restart iff tirex-backend-manager exits with exit status 2. Exit 2 can happen in the last commit. --- debian/tirex-backend-manager.service | 1 + 1 file changed, 1 insertion(+) diff --git a/debian/tirex-backend-manager.service b/debian/tirex-backend-manager.service index 728ba00..d8da684 100644 --- a/debian/tirex-backend-manager.service +++ b/debian/tirex-backend-manager.service @@ -9,6 +9,7 @@ ExecStart=/usr/bin/tirex-backend-manager -f ExecReload=/bin/kill -HUP $MAINPID KillMode=process Restart=on-failure +RestartPreventExitStatus=INVALIDARGUMENT User=_tirex Group=_tirex