[services-openrc] Introduce *mandatory* subkey
- Follow services-systemd and have a *mandatory* subkey that selects for install-failure instead of just a warning. FIXES #992
This commit is contained in:
parent
72c0d1a101
commit
73ecd7320c
@ -56,9 +56,11 @@ class OpenrcController:
|
|||||||
if isinstance(svc, str):
|
if isinstance(svc, str):
|
||||||
name = svc
|
name = svc
|
||||||
runlevel = "default"
|
runlevel = "default"
|
||||||
|
mandatory = False
|
||||||
else:
|
else:
|
||||||
name = svc["name"]
|
name = svc["name"]
|
||||||
runlevel = svc.get("runlevel", "default")
|
runlevel = svc.get("runlevel", "default")
|
||||||
|
mandatory = svc.get("mandatory", False)
|
||||||
|
|
||||||
service_path = self.root + self.initdDir + "/" + name
|
service_path = self.root + self.initdDir + "/" + name
|
||||||
runlevel_path = self.root + self.runlevelsDir + "/" + runlevel
|
runlevel_path = self.root + self.runlevelsDir + "/" + runlevel
|
||||||
@ -67,9 +69,22 @@ class OpenrcController:
|
|||||||
if exists(runlevel_path):
|
if exists(runlevel_path):
|
||||||
ec = target_env_call(["rc-update", state, name, runlevel])
|
ec = target_env_call(["rc-update", state, name, runlevel])
|
||||||
if ec != 0:
|
if ec != 0:
|
||||||
|
if mandatory:
|
||||||
|
return ("Cannot {} service {} to {}".format(state, name, runlevel),
|
||||||
|
"rc-update {} call in chroot returned error code {}".format(state, ec)
|
||||||
|
)
|
||||||
|
else:
|
||||||
warning("Could not {} service {} in {}, error {!s}".format(state, name, runlevel, ec))
|
warning("Could not {} service {} in {}, error {!s}".format(state, name, runlevel, ec))
|
||||||
|
else:
|
||||||
|
if mandatory:
|
||||||
|
return ("Target runlevel {} does not exist for {}.".format(runlevel, name),
|
||||||
|
"No {} found.".format(runlevel_path))
|
||||||
else:
|
else:
|
||||||
warning("Target runlevel {} does not exist for {}.".format(runlevel, name))
|
warning("Target runlevel {} does not exist for {}.".format(runlevel, name))
|
||||||
|
else:
|
||||||
|
if mandatory:
|
||||||
|
return ("Target service {} does not exist.".format(name),
|
||||||
|
"No {} found.".format(service_path))
|
||||||
else:
|
else:
|
||||||
warning("Target service {} does not exist in {}.".format(name, self.initdDir))
|
warning("Target service {} does not exist in {}.".format(name, self.initdDir))
|
||||||
|
|
||||||
@ -79,7 +94,9 @@ class OpenrcController:
|
|||||||
"""
|
"""
|
||||||
|
|
||||||
for state in ("add", "del"):
|
for state in ("add", "del"):
|
||||||
self.update(state)
|
r = self.update(state)
|
||||||
|
if r is not None:
|
||||||
|
return r
|
||||||
|
|
||||||
def run():
|
def run():
|
||||||
"""
|
"""
|
||||||
|
@ -16,20 +16,25 @@ runlevelsDir: /etc/runlevels
|
|||||||
# services: a list of entries to **enable**
|
# services: a list of entries to **enable**
|
||||||
# disable: a list of entries to **disable**
|
# disable: a list of entries to **disable**
|
||||||
#
|
#
|
||||||
# Each entry has two fields:
|
# Each entry has three fields:
|
||||||
# - name: the service name
|
# - name: the service name
|
||||||
# - runlevel: can hold any runlevel present on the target system;
|
# - (optional) runlevel: can hold any runlevel present on the target
|
||||||
# if no runlevel is provided, "default" is assumed.
|
# system; if no runlevel is provided, "default" is assumed.
|
||||||
|
# - (optional) mandatory: if set to true, a failure to modify
|
||||||
|
# the service will result in installation failure, rather than just
|
||||||
|
# a warning. The default is false.
|
||||||
|
#
|
||||||
# an entry may also be a single string, which is interpreted
|
# an entry may also be a single string, which is interpreted
|
||||||
# as the name field (runlevel "default" is assumed then).
|
# as the name field (runlevel "default" is assumed then, and not-mandatory).
|
||||||
#
|
#
|
||||||
# # Example services and disable settings:
|
# # Example services and disable settings:
|
||||||
# # - add foo1 to default
|
# # - add foo1 to default, but it must succeed
|
||||||
# # - add foo2 to nonetwork
|
# # - add foo2 to nonetwork
|
||||||
# # - remove foo3 from default
|
# # - remove foo3 from default
|
||||||
# # - remove foo4 from default
|
# # - remove foo4 from default
|
||||||
# services:
|
# services:
|
||||||
# - name: foo1
|
# - name: foo1
|
||||||
|
# mandatory: true
|
||||||
# - name: foo2
|
# - name: foo2
|
||||||
# runlevel: nonetwork
|
# runlevel: nonetwork
|
||||||
# disable:
|
# disable:
|
||||||
|
Loading…
Reference in New Issue
Block a user