From 993be1086ed05661fbdec6a3f7df7eb92d6812f1 Mon Sep 17 00:00:00 2001 From: Veiko Aasa Date: Tue, 29 Dec 2020 13:26:15 +0200 Subject: [PATCH] plinth: Fix daemon is enabled check when service alias is provided For a service alias, the `systemctl is-enabled ...` command returns 'alias'. Mark a daemon as running if one of the provided services returns 'running'. Tests performed: - All the bind app tests pass Signed-off-by: Veiko Aasa [sunil: Added comment about better implementation] Signed-off-by: Sunil Mohan Adapa Reviewed-by: Sunil Mohan Adapa --- plinth/daemon.py | 25 +++++++++++++++++++------ 1 file changed, 19 insertions(+), 6 deletions(-) diff --git a/plinth/daemon.py b/plinth/daemon.py index 144eb85d4..3d04f5ca7 100644 --- a/plinth/daemon.py +++ b/plinth/daemon.py @@ -34,12 +34,12 @@ class Daemon(app.LeaderComponent): is renamed, the new unit file usually contains an Alias= setting in [Install] section with value of old unit name. When the unit is enabled, a symlink with the name of the alias is created. All - operations such as is-enabled, is-running and disable work with the - alias along with the primary unit name. However, for the case of - enabling the unit file, the alias does not work. To be able to provide - management for multiple versions of the unit file with different names, - specify an alias. Both the names are taken into consideration when - enabling the unit file. + operations such as is-running and disable work with the alias along + with the primary unit name. However, for the case of enabling the unit + file or checking its enabled status, the alias does not work. To be + able to provide management for multiple versions of the unit file with + different names, specify an alias. Both the names are taken into + consideration when enabling the unit file. """ super().__init__(component_id) @@ -51,6 +51,19 @@ class Daemon(app.LeaderComponent): def is_enabled(self): """Return if the daemon/unit is enabled.""" + if self.alias: + # XXX: Handling alias should not be done here. service_is_enabled() + # should return True even for an alias. Currently, in addition to + # return code we are also checking the printed value. This makes + # the implementation less future-proof as new values could printed + # by the command. A fixed systemd bug + # https://github.com/systemd/systemd/issues/18134 also currently + # gives incorrect exit code for 'alias' case. See: + # https://salsa.debian.org/freedombox-team/freedombox/-/merge_requests/1980 + if action_utils.service_is_enabled(self.alias, + strict_check=self.strict_check): + return True + return action_utils.service_is_enabled(self.unit, strict_check=self.strict_check)