From 5611585790b08a9832ca72a5cfc3e7997ddd0e06 Mon Sep 17 00:00:00 2001 From: Sunil Mohan Adapa Date: Tue, 1 Oct 2024 19:32:11 -0700 Subject: [PATCH] names: Schedule a task to install systemd-resolved when possible - Don't schedule if the package is already installed. Tests: - With systemd-resolved installed and without internet connectivity start a fresh instance (without first setup). Setup succeeds but systemd-resolved is not installed. - Wait in develop mode for 180 seconds. Setup for names app is re-run. Ensure that internet connectivity is not available and systemd-package is not installed. Setup still succeeds. - On next run, ensure that internet connectivity is available, systemd-resolved is installed. Setup succeeds. - On next run, setup is not re-run for names app. - When service is restarted, the task is not even scheduled. Signed-off-by: Sunil Mohan Adapa Reviewed-by: Veiko Aasa --- plinth/modules/names/__init__.py | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/plinth/modules/names/__init__.py b/plinth/modules/names/__init__.py index c46ca09ad..54597ea17 100644 --- a/plinth/modules/names/__init__.py +++ b/plinth/modules/names/__init__.py @@ -12,7 +12,7 @@ from django.utils.translation import gettext_lazy as _ from django.utils.translation import gettext_noop from plinth import app as app_module -from plinth import cfg, menu, network +from plinth import cfg, glib, menu, network, setup from plinth.daemon import Daemon from plinth.diagnostic_check import (DiagnosticCheck, DiagnosticCheckParameters, Result) @@ -90,6 +90,11 @@ class NamesApp(app_module.App): domain_type='domain-type-static', name=domain_name, services='__all__') + # Schedule installation of systemd-resolved if not already installed. + if not is_resolved_installed(): + # Try to install the package hourly. + glib.schedule(3600, install_systemd_resolved) + def diagnose(self) -> list[DiagnosticCheck]: """Run diagnostics and return the results.""" results = super().diagnose() @@ -171,6 +176,12 @@ class ResolvedDaemon(Daemon): return super().diagnose() +def install_systemd_resolved(_data): + """Re-run setup on app to install systemd-resolved.""" + if not is_resolved_installed(): + setup.run_setup_on_app('names', rerun=True) + + def diagnose_resolution(domain: str) -> DiagnosticCheck: """Perform a diagnostic check for whether a domain can be resolved.""" result = Result.NOT_DONE