[services-systemd] Follow the flexible example of openrc

- Make *mandatory* optional (and default to false); this
   allows shorter lists of entries
 - Allow degenerate entries which are just a name
   (which have *mandatory* set to false as well).

SEE #992
This commit is contained in:
Adriaan de Groot 2018-06-27 11:25:11 -04:00
parent 73ecd7320c
commit 1957478618
2 changed files with 20 additions and 6 deletions

View File

@ -35,18 +35,25 @@ def systemctl(targets, command, suffix):
silently.
"""
for svc in targets:
if isinstance(svc, str):
name = svc
mandatory = False
else:
name = svc["name"]
mandatory = svc.get("mandatory", False)
ec = libcalamares.utils.target_env_call(
['systemctl', command, "{}{}".format(svc['name'], suffix)]
['systemctl', command, "{}{}".format(name, suffix)]
)
if ec != 0:
if svc['mandatory']:
return ("Cannot {} systemd {} {}".format(command, suffix, svc['name']),
if mandatory:
return ("Cannot {} systemd {} {}".format(command, suffix, name),
"systemctl {} call in chroot returned error code {}".format(command, ec)
)
else:
libcalamares.utils.warning(
"Cannot {} systemd {} {}".format(command, suffix, svc['name'])
"Cannot {} systemd {} {}".format(command, suffix, name)
)
libcalamares.utils.warning(
"systemctl {} call in chroot returned error code {}".format(command, ec)

View File

@ -17,7 +17,12 @@
# - *mandatory* is a boolean option, which states whether the change
# must be done successfully. If systemd reports an error while changing
# a mandatory entry, the installation will fail. When mandatory is false,
# errors for that entry (service or target) are ignored.
# errors for that entry (service or target) are ignored. If mandatory
# is not specified, the default is false.
#
# An entry may also be given as a single string, which is then
# interpreted as the name of the service. In this case, mandatory
# is also set to the default of false.
#
# Use [] to express an empty list.
@ -44,7 +49,9 @@
# mandatory: false
#
# # Disables <name>.target
# disable-targets: []
# # .. this shows how to use just the name
# disable-targets:
# - graphical
#
# # Masks (stronger version of disable). This section
# # is unusual because you **must** include the suffix