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 <sunil@medhas.org>
Reviewed-by: Veiko Aasa <veiko17@disroot.org>
This commit is contained in:
Sunil Mohan Adapa 2024-10-01 19:32:11 -07:00 committed by Veiko Aasa
parent 7e8819d7d5
commit 5611585790
No known key found for this signature in database
GPG Key ID: 478539CAE680674E

View File

@ -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