[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:
Adriaan de Groot 2018-06-27 11:11:21 -04:00
parent 72c0d1a101
commit 73ecd7320c
2 changed files with 31 additions and 9 deletions

View File

@ -56,9 +56,11 @@ class OpenrcController:
if isinstance(svc, str):
name = svc
runlevel = "default"
mandatory = False
else:
name = svc["name"]
runlevel = svc.get("runlevel", "default")
mandatory = svc.get("mandatory", False)
service_path = self.root + self.initdDir + "/" + name
runlevel_path = self.root + self.runlevelsDir + "/" + runlevel
@ -67,11 +69,24 @@ class OpenrcController:
if exists(runlevel_path):
ec = target_env_call(["rc-update", state, name, runlevel])
if ec != 0:
warning("Could not {} service {} in {}, error {!s}".format(state, name, runlevel, ec))
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))
else:
warning("Target runlevel {} does not exist for {}.".format(runlevel, name))
if mandatory:
return ("Target runlevel {} does not exist for {}.".format(runlevel, name),
"No {} found.".format(runlevel_path))
else:
warning("Target runlevel {} does not exist for {}.".format(runlevel, name))
else:
warning("Target service {} does not exist in {}.".format(name, self.initdDir))
if mandatory:
return ("Target service {} does not exist.".format(name),
"No {} found.".format(service_path))
else:
warning("Target service {} does not exist in {}.".format(name, self.initdDir))
def run(self):
@ -79,7 +94,9 @@ class OpenrcController:
"""
for state in ("add", "del"):
self.update(state)
r = self.update(state)
if r is not None:
return r
def run():
"""

View File

@ -16,20 +16,25 @@ runlevelsDir: /etc/runlevels
# services: a list of entries to **enable**
# disable: a list of entries to **disable**
#
# Each entry has two fields:
# Each entry has three fields:
# - name: the service name
# - runlevel: can hold any runlevel present on the target system;
# if no runlevel is provided, "default" is assumed.
# - (optional) runlevel: can hold any runlevel present on the target
# 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
# 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:
# # - add foo1 to default
# # - add foo1 to default, but it must succeed
# # - add foo2 to nonetwork
# # - remove foo3 from default
# # - remove foo4 from default
# services:
# - name: foo1
# mandatory: true
# - name: foo2
# runlevel: nonetwork
# disable: