[services-systemd] Refactor getting config
- Don't create temporary variables - Change API slightly to accomodate more (kinds of) suffixes
This commit is contained in:
parent
0520fc3b7e
commit
5d6e07712b
@ -27,7 +27,7 @@ def systemctl(targets, command, suffix):
|
|||||||
"""
|
"""
|
||||||
For each entry in @p targets, run "systemctl <command> <thing>",
|
For each entry in @p targets, run "systemctl <command> <thing>",
|
||||||
where <thing> is the entry's name plus the given @p suffix.
|
where <thing> is the entry's name plus the given @p suffix.
|
||||||
A dot is added between name and suffix.
|
(No dot is added between name and suffix; suffix may be empty)
|
||||||
|
|
||||||
Returns a failure message, or None if this was successful.
|
Returns a failure message, or None if this was successful.
|
||||||
Services that are not mandatory have their failures suppressed
|
Services that are not mandatory have their failures suppressed
|
||||||
@ -35,7 +35,7 @@ def systemctl(targets, command, suffix):
|
|||||||
"""
|
"""
|
||||||
for svc in targets:
|
for svc in targets:
|
||||||
ec = libcalamares.utils.target_env_call(
|
ec = libcalamares.utils.target_env_call(
|
||||||
['systemctl', command, "{}.{}".format(svc['name'], suffix)]
|
['systemctl', command, "{}{}".format(svc['name'], suffix)]
|
||||||
)
|
)
|
||||||
|
|
||||||
if ec != 0:
|
if ec != 0:
|
||||||
@ -57,24 +57,22 @@ def run():
|
|||||||
"""
|
"""
|
||||||
Setup systemd services
|
Setup systemd services
|
||||||
"""
|
"""
|
||||||
services = libcalamares.job.configuration['services']
|
cfg = libcalamares.job.configuration
|
||||||
targets = libcalamares.job.configuration['targets']
|
|
||||||
disable = libcalamares.job.configuration['disable']
|
|
||||||
|
|
||||||
# note that the "systemctl enable" and "systemctl disable" commands used
|
# note that the "systemctl enable" and "systemctl disable" commands used
|
||||||
# here will work in a chroot; in fact, they are the only systemctl commands
|
# here will work in a chroot; in fact, they are the only systemctl commands
|
||||||
# that support that, see:
|
# that support that, see:
|
||||||
# http://0pointer.de/blog/projects/changing-roots.html
|
# http://0pointer.de/blog/projects/changing-roots.html
|
||||||
|
|
||||||
r = systemctl(services, "enable", "service")
|
r = systemctl(cfg["services"], "enable", ".service")
|
||||||
if r is not None:
|
if r is not None:
|
||||||
return r
|
return r
|
||||||
|
|
||||||
r = systemctl(targets, "enable", "target")
|
r = systemctl(cfg["targets"], "enable", ".target")
|
||||||
if r is not None:
|
if r is not None:
|
||||||
return r
|
return r
|
||||||
|
|
||||||
r = systemctl(disable, "disable", "service")
|
r = systemctl(cfg["disable"], "disable", ".service")
|
||||||
if r is not None:
|
if r is not None:
|
||||||
return r
|
return r
|
||||||
|
|
||||||
|
@ -12,7 +12,8 @@
|
|||||||
# *services*, *targets* and *disable*. The value of each
|
# *services*, *targets* and *disable*. The value of each
|
||||||
# key is a list of entries. Each entry has two keys:
|
# key is a list of entries. Each entry has two keys:
|
||||||
# - *name* is the (string) name of the service or target that is being
|
# - *name* is the (string) name of the service or target that is being
|
||||||
# changed. Use quotes.
|
# changed. Use quotes. Don't include ".target" or ".service"
|
||||||
|
# in the name.
|
||||||
# - *mandatory* is a boolean option, which states whether the change
|
# - *mandatory* is a boolean option, which states whether the change
|
||||||
# must be done successfully. If systemd reports an error while changing
|
# must be done successfully. If systemd reports an error while changing
|
||||||
# a mandatory entry, the installation will fail. When mandatory is false,
|
# a mandatory entry, the installation will fail. When mandatory is false,
|
||||||
@ -25,16 +26,19 @@
|
|||||||
# # graphical target (e.g. so that SDDM runs for login), and
|
# # graphical target (e.g. so that SDDM runs for login), and
|
||||||
# # finally disables pacman-init (an ArchLinux-only service).
|
# # finally disables pacman-init (an ArchLinux-only service).
|
||||||
# #
|
# #
|
||||||
|
# # Enables <name>.service
|
||||||
# services:
|
# services:
|
||||||
# - name: "NetworkManager"
|
# - name: "NetworkManager"
|
||||||
# mandatory: true
|
# mandatory: true
|
||||||
# - name: "cups"
|
# - name: "cups"
|
||||||
# mandatory: false
|
# mandatory: false
|
||||||
#
|
#
|
||||||
|
# # Enables <name>.target
|
||||||
# targets:
|
# targets:
|
||||||
# - name: "graphical"
|
# - name: "graphical"
|
||||||
# mandatory: true
|
# mandatory: true
|
||||||
#
|
#
|
||||||
|
# # Disables <name>.service
|
||||||
# disable:
|
# disable:
|
||||||
# - name: "pacman-init"
|
# - name: "pacman-init"
|
||||||
# mandatory: false
|
# mandatory: false
|
||||||
|
Loading…
Reference in New Issue
Block a user