From f9ca06dc5f66ae246df561435fd4e2c12d923ee9 Mon Sep 17 00:00:00 2001 From: Sunil Mohan Adapa Date: Tue, 23 Sep 2025 16:25:28 -0700 Subject: [PATCH] daemon: When ensuring running state handle not-installed state Tests: - Uninstall miniflux and postgresql. Install freshly with all the patches in this series. When installing miniflux freshly, postgresql is not disabled soon after miniflux package is installed. Without this patch, postgresql is disabled after packages are installed leading to a setup failure. Signed-off-by: Sunil Mohan Adapa Reviewed-by: James Valleroy --- plinth/daemon.py | 7 +++++++ plinth/tests/test_daemon.py | 13 +++++++++++-- 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/plinth/daemon.py b/plinth/daemon.py index 9c8fba8d9..8b91a8148 100644 --- a/plinth/daemon.py +++ b/plinth/daemon.py @@ -91,6 +91,13 @@ class Daemon(app.LeaderComponent, log.LogEmitter): def ensure_running(self): """Ensure a service is running and return to previous state.""" from plinth.privileged import service as service_privileged + + if action_utils.service_show(self.unit)['LoadState'] == 'not-found': + # The service's package not installed yet, don't try to start it + # and later stop it after it is installed. + yield False # Not running + return + starting_state = self.is_running() if not starting_state: service_privileged.enable(self.unit) diff --git a/plinth/tests/test_daemon.py b/plinth/tests/test_daemon.py index 2fe05179c..879774db2 100644 --- a/plinth/tests/test_daemon.py +++ b/plinth/tests/test_daemon.py @@ -145,12 +145,21 @@ def test_is_running(service_is_running, daemon): @patch('plinth.app.apps_init') @patch('plinth.action_utils.service_is_running') +@patch('plinth.action_utils.service_show') @patch('subprocess.run') -def test_ensure_running(subprocess_run, service_is_running, apps_init, - app_list, mock_privileged, daemon): +def test_ensure_running(subprocess_run, service_show, service_is_running, + apps_init, app_list, mock_privileged, daemon): """Test that checking that the daemon is running works.""" common_args = dict(stdout=subprocess.PIPE, stderr=subprocess.PIPE, check=False) + + service_show.return_value = {'LoadState': 'not-found'} + with daemon.ensure_running() as starting_state: + assert not starting_state + assert subprocess_run.mock_calls == [] + + service_show.return_value = {'LoadState': 'loaded'} + service_is_running.return_value = True with daemon.ensure_running() as starting_state: assert starting_state