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