From 73ecd7320c1b44c4406268e2d2a7866c2e69379b Mon Sep 17 00:00:00 2001 From: Adriaan de Groot Date: Wed, 27 Jun 2018 11:11:21 -0400 Subject: [PATCH] [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 --- src/modules/services-openrc/main.py | 25 ++++++++++++++++--- .../services-openrc/services-openrc.conf | 15 +++++++---- 2 files changed, 31 insertions(+), 9 deletions(-) diff --git a/src/modules/services-openrc/main.py b/src/modules/services-openrc/main.py index 6f1d7352b..c3e14b481 100644 --- a/src/modules/services-openrc/main.py +++ b/src/modules/services-openrc/main.py @@ -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(): """ diff --git a/src/modules/services-openrc/services-openrc.conf b/src/modules/services-openrc/services-openrc.conf index 168fa190a..b8255b21a 100644 --- a/src/modules/services-openrc/services-openrc.conf +++ b/src/modules/services-openrc/services-openrc.conf @@ -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: