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 <veiko17@disroot.org>
[sunil: Added comment about better implementation]
Signed-off-by: Sunil Mohan Adapa <sunil@medhas.org>
Reviewed-by: Sunil Mohan Adapa <sunil@medhas.org>
This commit is contained in:
Veiko Aasa 2020-12-29 13:26:15 +02:00 committed by Sunil Mohan Adapa
parent 504d0cdf00
commit 993be1086e
No known key found for this signature in database
GPG Key ID: 43EA1CFF0AA7C5F2

View File

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