From 10f670ab7e043c252459f6e7a4bcc47008bdb602 Mon Sep 17 00:00:00 2001 From: Oliver Schmidt Date: Tue, 14 Jan 2025 15:41:34 +0100 Subject: [PATCH 1/2] nixos/matomo: better check for database being set up Since matomo-5.2.0, the config.php.ini is already created when first accessing the installer page without completing it. This breaks our discovery of whether to run database migrations. Attempting to run DB migrations without provided database credentials causes a crash -> causing matomo-setup-update.service to fail -> causing phpfpm-matomo.service to fail. --- nixos/modules/services/web-apps/matomo.nix | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/nixos/modules/services/web-apps/matomo.nix b/nixos/modules/services/web-apps/matomo.nix index a4bc04edf0640..73f93778bf0bd 100644 --- a/nixos/modules/services/web-apps/matomo.nix +++ b/nixos/modules/services/web-apps/matomo.nix @@ -183,7 +183,10 @@ in { chmod -R u+rwX,g+rwX,o-rwx "${dataDir}" # check whether user setup has already been done - if test -f "${dataDir}/config/config.ini.php"; then + if test -f "${dataDir}/config/config.ini.php" && + # since matomo-5.2.0, the config.ini.php is already created at first + # installer page access https://github.com/matomo-org/matomo/issues/22932 + grep -q -F "[database]" "${dataDir}/config/config.ini.php"; then # then execute possibly pending database upgrade matomo-console core:update --yes fi From fc6d9cc539f4bd0df99466dce003d141b17ae528 Mon Sep 17 00:00:00 2001 From: Oliver Schmidt Date: Tue, 14 Jan 2025 16:01:30 +0100 Subject: [PATCH 2/2] nixosTests.matomo: extend test coverage --- nixos/tests/matomo.nix | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/nixos/tests/matomo.nix b/nixos/tests/matomo.nix index 35c71aa088538..1a40fa93a5578 100644 --- a/nixos/tests/matomo.nix +++ b/nixos/tests/matomo.nix @@ -37,11 +37,25 @@ let machine.wait_for_unit("phpfpm-matomo.service") machine.wait_for_unit("nginx.service") + with subtest("matomo.js reachable via HTTP"): + machine.succeed("curl -sSfk http://machine/matomo.js") + + with subtest("js/piwik.js reachable via HTTP"): + machine.succeed("curl -sSfk http://machine/js/piwik.js") + + with subtest("matomo.php (API) reachable via HTTP"): + machine.succeed("curl -sSfk http://machine/matomo.php") + # without the grep the command does not produce valid utf-8 for some reason with subtest("welcome screen loads"): machine.succeed( "curl -sSfL http://localhost/ | grep 'Matomo[^<]*Installation'" ) + + with subtest("killing the phpfpm process should trigger an automatic restart"): + machine.succeed("systemctl kill -s KILL phpfpm-matomo") + machine.sleep(1) + machine.wait_for_unit("phpfpm-matomo.service") ''; }; in