From 61da6124edee4f9735d50a412d5ecc16c8eec674 Mon Sep 17 00:00:00 2001 From: Sayan Paul Date: Tue, 8 Aug 2023 09:56:04 -0400 Subject: [PATCH] stages/systemd:support for user service dropin systemd unit stage will now be able to add user unit dropin, this is done by adding an additional field:unit-type which is set to system by default. It also adds ability to update the unit config with ConditionPathExists. Relevant testing updated for the new workflow. Signed-off-by: Sayan Paul --- stages/org.osbuild.systemd.unit | 23 ++++++++++++++++++++++- test/data/stages/systemd.unit/b.json | 13 +++++++++++++ test/data/stages/systemd.unit/b.mpp.yaml | 8 ++++++++ test/data/stages/systemd.unit/diff.json | 4 +++- 4 files changed, 46 insertions(+), 2 deletions(-) diff --git a/stages/org.osbuild.systemd.unit b/stages/org.osbuild.systemd.unit index af0f0e01..dc97b14c 100755 --- a/stages/org.osbuild.systemd.unit +++ b/stages/org.osbuild.systemd.unit @@ -39,6 +39,17 @@ SCHEMA = r""" "type": "object", "description": "Drop-in configuration for a '.service' unit.", "properties": { + "Unit": { + "additionalProperties": false, + "type": "object", + "description": "'Unit' configuration section of a unit file.", + "properties": { + "ConditionPathExists": { + "type": "string", + "description": "Check for the existence of a file. If the specified absolute path name does not exist, the condition will fail." + } + } + }, "Service": { "additionalProperties": false, "type": "object", @@ -51,6 +62,12 @@ SCHEMA = r""" } } } + }, + "unit-type": { + "type": "string", + "enum": ["system", "global"], + "default": "system", + "description": "Selects between systemd system or global unit to add dropin" } } """ @@ -60,12 +77,16 @@ def main(tree, options): unit = options["unit"] dropin_file = options["dropin"] cfg = options["config"] + unit_type = options.get("unit-type", "system") # ensure the unit name + ".d" does not exceed maximum filename length if len(unit + ".d") > 255: raise ValueError(f"Error: the {unit} unit drop-in directory exceeds the maximum filename length.") - unit_dropins_dir = f"{tree}/usr/lib/systemd/system/{unit}.d" + if unit_type == "system": + unit_dropins_dir = f"{tree}/usr/lib/systemd/system/{unit}.d" + elif unit_type == "global": + unit_dropins_dir = f"{tree}/usr/lib/systemd/user/{unit}.d" os.makedirs(unit_dropins_dir, exist_ok=True) config = configparser.ConfigParser() diff --git a/test/data/stages/systemd.unit/b.json b/test/data/stages/systemd.unit/b.json index 636c1d61..796e84c3 100644 --- a/test/data/stages/systemd.unit/b.json +++ b/test/data/stages/systemd.unit/b.json @@ -470,6 +470,19 @@ } } } + }, + { + "name": "org.osbuild.systemd.unit", + "options": { + "unit": "grub-boot-success.timer", + "dropin": "10-disable-if-greenboot.conf", + "unit-type": "global", + "config": { + "Unit": { + "ConditionPathExists": "/usr/lib/greenboot/greenboot" + } + } + } } ] }, diff --git a/test/data/stages/systemd.unit/b.mpp.yaml b/test/data/stages/systemd.unit/b.mpp.yaml index b64c17ce..2544a40d 100644 --- a/test/data/stages/systemd.unit/b.mpp.yaml +++ b/test/data/stages/systemd.unit/b.mpp.yaml @@ -26,3 +26,11 @@ pipeline: config: Service: Environment: NM_CLOUD_SETUP_EC2=yes + - name: org.osbuild.systemd.unit + options: + unit: grub-boot-success.timer + dropin: 10-disable-if-greenboot.conf + unit-type: global + config: + Unit: + ConditionPathExists: /usr/lib/greenboot/greenboot diff --git a/test/data/stages/systemd.unit/diff.json b/test/data/stages/systemd.unit/diff.json index 6222eff5..fedb6dfe 100644 --- a/test/data/stages/systemd.unit/diff.json +++ b/test/data/stages/systemd.unit/diff.json @@ -1,7 +1,9 @@ { "added_files": [ "/usr/lib/systemd/system/nm-cloud-setup.service.d", - "/usr/lib/systemd/system/nm-cloud-setup.service.d/10-rh-enable-for-ec2.conf" + "/usr/lib/systemd/system/nm-cloud-setup.service.d/10-rh-enable-for-ec2.conf", + "/usr/lib/systemd/user/grub-boot-success.timer.d", + "/usr/lib/systemd/user/grub-boot-success.timer.d/10-disable-if-greenboot.conf" ], "deleted_files": [], "differences": {}