From 766477214b80749908e62068d377338a4924c2d0 Mon Sep 17 00:00:00 2001 From: Peter van Arkel Date: Sat, 21 Nov 2026 23:21:08 +0100 Subject: [PATCH] Use Debian 13 PHP-FPM packages for managed websites --- deploy/systemd/coulobre-https-apply@.service | 2 +- deploy/systemd/coulobre-web-apply@.service | 2 +- src/coulobre/hosting/test_php_settings.py | 4 +-- src/coulobre/hosting/test_web_node_apply.py | 26 +++++++++++++++++--- src/coulobre/php_runtime.py | 18 ++++++++++++++ src/coulobre/service_health.py | 4 ++- src/coulobre/web_node.py | 4 +-- src/coulobre/web_node_apply.py | 5 ++-- src/coulobre/web_node_php.py | 2 +- src/coulobre/web_node_retirement.py | 2 +- 10 files changed, 53 insertions(+), 16 deletions(-) create mode 100644 src/coulobre/php_runtime.py diff --git a/deploy/systemd/coulobre-https-apply@.service b/deploy/systemd/coulobre-https-apply@.service index 542b3eb..b0c5b3d 100644 --- a/deploy/systemd/coulobre-https-apply@.service +++ b/deploy/systemd/coulobre-https-apply@.service @@ -1,6 +1,6 @@ [Unit] Description=Coulobre local website HTTPS request -After=apache2.service php8.5-fpm.service +After=apache2.service php8.4-fpm.service php8.5-fpm.service CollectMode=inactive-or-failed [Service] diff --git a/deploy/systemd/coulobre-web-apply@.service b/deploy/systemd/coulobre-web-apply@.service index 700b0ab..8598f57 100644 --- a/deploy/systemd/coulobre-web-apply@.service +++ b/deploy/systemd/coulobre-web-apply@.service @@ -1,6 +1,6 @@ [Unit] Description=Coulobre local web activation request -After=apache2.service php8.5-fpm.service +After=apache2.service php8.4-fpm.service php8.5-fpm.service CollectMode=inactive-or-failed [Service] diff --git a/src/coulobre/hosting/test_php_settings.py b/src/coulobre/hosting/test_php_settings.py index d811537..67378e9 100644 --- a/src/coulobre/hosting/test_php_settings.py +++ b/src/coulobre/hosting/test_php_settings.py @@ -9,9 +9,9 @@ from django.urls import reverse from django.utils import timezone from coulobre.php_pool_settings import PhpPoolSettings +from coulobre.php_runtime import PHP_FPM_BINARY, PHP_SERVICE from coulobre.web_node import WebPhpRequest, WebSite, parse_web_request from coulobre.web_node_apply import ( - PHP_SERVICE, SitePaths, install_configurations, ) @@ -284,7 +284,7 @@ class NativePhpSettingsTests(SimpleTestCase): self.assertEqual( self.runner.call_args_list, [ - call("/usr/sbin/php-fpm8.5", "--test"), + call(PHP_FPM_BINARY, "--test"), call("/usr/sbin/service", PHP_SERVICE, "reload"), call("/usr/sbin/service", PHP_SERVICE, "reload"), ], diff --git a/src/coulobre/hosting/test_web_node_apply.py b/src/coulobre/hosting/test_web_node_apply.py index 30ae41c..22c59d9 100644 --- a/src/coulobre/hosting/test_web_node_apply.py +++ b/src/coulobre/hosting/test_web_node_apply.py @@ -5,10 +5,30 @@ from unittest.mock import call, patch from django.test import SimpleTestCase +from coulobre.php_runtime import PHP_FPM_BINARY, PHP_SERVICE, php_fpm_version from coulobre.web_node import WebSite from coulobre.web_node_apply import install_configurations, site_status +class PhpRuntimeTests(SimpleTestCase): + @patch("coulobre.php_runtime.freedesktop_os_release") + def test_selects_the_packaged_fpm_version(self, release): + for distribution, version, expected in ( + ("debian", "13", "8.4"), + ("ubuntu", "26.04", "8.5"), + ): + with self.subTest(distribution=distribution, version=version): + release.return_value = { + "ID": distribution, + "VERSION_ID": version, + } + self.assertEqual(php_fpm_version(), expected) + + @patch("coulobre.php_runtime.freedesktop_os_release", side_effect=OSError) + def test_missing_os_release_keeps_the_default_version(self, release): + self.assertEqual(php_fpm_version(), "8.5") + + class WebNodeConfigurationTests(SimpleTestCase): def setUp(self): directory = Path(self.enterContext(TemporaryDirectory())) @@ -40,9 +60,9 @@ class WebNodeConfigurationTests(SimpleTestCase): self.assertEqual( self.runner.call_args_list, [ - call("/usr/sbin/php-fpm8.5", "--test"), + call(PHP_FPM_BINARY, "--test"), call("/usr/sbin/apache2ctl", "configtest"), - call("/usr/sbin/service", "php8.5-fpm", "reload"), + call("/usr/sbin/service", PHP_SERVICE, "reload"), call("/usr/sbin/service", "apache2", "reload"), ], ) @@ -68,7 +88,7 @@ class WebNodeConfigurationTests(SimpleTestCase): self.assertEqual( self.runner.call_args_list[-2:], [ - call("/usr/sbin/service", "php8.5-fpm", "reload"), + call("/usr/sbin/service", PHP_SERVICE, "reload"), call("/usr/sbin/service", "apache2", "reload"), ], ) diff --git a/src/coulobre/php_runtime.py b/src/coulobre/php_runtime.py new file mode 100644 index 0000000..65fe25b --- /dev/null +++ b/src/coulobre/php_runtime.py @@ -0,0 +1,18 @@ +from pathlib import Path +from platform import freedesktop_os_release + + +def php_fpm_version(): + try: + release = freedesktop_os_release() + except OSError: + release = {} + if release.get("ID") == "debian" and release.get("VERSION_ID") == "13": + return "8.4" + return "8.5" + + +PHP_VERSION = php_fpm_version() +PHP_SERVICE = f"php{PHP_VERSION}-fpm" +PHP_FPM_BINARY = f"/usr/sbin/php-fpm{PHP_VERSION}" +PHP_POOL_DIRECTORY = Path(f"/etc/php/{PHP_VERSION}/fpm/pool.d") diff --git a/src/coulobre/service_health.py b/src/coulobre/service_health.py index 4033dc7..c7e6f7a 100644 --- a/src/coulobre/service_health.py +++ b/src/coulobre/service_health.py @@ -4,12 +4,14 @@ import subprocess from dataclasses import dataclass from enum import StrEnum +from .php_runtime import PHP_SERVICE, PHP_VERSION + SERVICES = { "panel": ("Coulobre Panel", "coulobre-panel.service"), "worker": ("Coulobre worker", "coulobre-worker.service"), "scheduler": ("Coulobre scheduler", "coulobre-beat.service"), "apache": ("Apache", "apache2.service"), - "php-fpm": ("PHP 8.5 FPM", "php8.5-fpm.service"), + "php-fpm": (f"PHP {PHP_VERSION} FPM", f"{PHP_SERVICE}.service"), "mariadb": ("MariaDB", "mariadb.service"), "rabbitmq": ("RabbitMQ", "rabbitmq-server.service"), "bind9": ("BIND9", "named.service"), diff --git a/src/coulobre/web_node.py b/src/coulobre/web_node.py index c101ae2..c8d95df 100644 --- a/src/coulobre/web_node.py +++ b/src/coulobre/web_node.py @@ -310,9 +310,7 @@ def main(argv=None): ) render.add_argument("manifest", type=Path) render.add_argument("configuration", choices=CONFIGURATIONS) - apply = commands.add_parser( - "apply", help="Install a site on an Ubuntu web node." - ) + apply = commands.add_parser("apply", help="Install a site on a web node.") apply.add_argument("manifest", type=Path) commands.add_parser( "apply-request", diff --git a/src/coulobre/web_node_apply.py b/src/coulobre/web_node_apply.py index 3cdc303..f3ddf56 100644 --- a/src/coulobre/web_node_apply.py +++ b/src/coulobre/web_node_apply.py @@ -16,13 +16,12 @@ from .node_files import ( require_root_directory, write_new_file, ) +from .php_runtime import PHP_FPM_BINARY, PHP_POOL_DIRECTORY, PHP_SERVICE STATE_DIRECTORY = Path("/var/lib/coulobre/web-node") WEB_ROOT = Path("/srv/coulobre/web") APACHE_AVAILABLE = Path("/etc/apache2/sites-available") APACHE_ENABLED = Path("/etc/apache2/sites-enabled") -PHP_POOL_DIRECTORY = Path("/etc/php/8.5/fpm/pool.d") -PHP_SERVICE = "php8.5-fpm" SITE_SHELL = "/usr/sbin/nologin" @@ -322,7 +321,7 @@ def install_configurations( ) enable_apache_site(apache, enabled, created) - run("/usr/sbin/php-fpm8.5", "--test") + run(PHP_FPM_BINARY, "--test") run("/usr/sbin/apache2ctl", "configtest") reload_attempts.append(PHP_SERVICE) run("/usr/sbin/service", PHP_SERVICE, "reload") diff --git a/src/coulobre/web_node_php.py b/src/coulobre/web_node_php.py index be1e346..a2b5310 100644 --- a/src/coulobre/web_node_php.py +++ b/src/coulobre/web_node_php.py @@ -46,7 +46,7 @@ def change_php_pool(paths, old, wanted): replace_pool_file(paths.pool, wanted) reload_attempted = False try: - web.run("/usr/sbin/php-fpm8.5", "--test") + web.run(web.PHP_FPM_BINARY, "--test") reload_attempted = True reload_php_pool(paths.socket) except (OSError, ValueError, KeyboardInterrupt) as error: diff --git a/src/coulobre/web_node_retirement.py b/src/coulobre/web_node_retirement.py index af37cc0..9ac5e66 100644 --- a/src/coulobre/web_node_retirement.py +++ b/src/coulobre/web_node_retirement.py @@ -104,7 +104,7 @@ def detach_site(site, paths, key_file, apache, retirement): for path, _, _, label in apache: archive_path(path, retirement.directory / label) archive_path(paths.pool, retirement.directory / "php-pool") - web.run("/usr/sbin/php-fpm8.5", "--test") + web.run(web.PHP_FPM_BINARY, "--test") web.run("/usr/sbin/service", web.PHP_SERVICE, "reload") archive_path(key_file, retirement.directory / "authorized-keys") archive_data_directory(